.htaccess does many internal loops - windows

#### BOF SSU
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /refm/
# Deny access from .htaccess
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1 [E=VAR1:$1,QSA,L]
#### EOF SSU
I've been using the same .htaccess code on Ubuntu and it was working fine, now I'm working on a windows machine and it doesn't seem to work, it always loads the homepage when I click on any on the inside pages. Basically, what this .htaccess does is to enable pretty permalinks for Zen Cart pages and products. The .htaccess file is recognized by Apache as I've checked the httpd.conf configurations, I checked error.log and here is the error that I found:
[error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
I've also changed the LogLevel to debug instead of warn to see the details of the error and here is what I got:
[Tue Jun 05 23:31:09 2012] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3065): [client 127.0.0.1] r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php/css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-
type-page-38
[Tue Jun 05 23:31:09 2012] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /css/style.css, referer: http://localhost/refm/refm-excel-products-by-property-type-page-38
So there seems to be some kind of loop. Can you help me figure it out? Thanks!

Try replacing your last rule with this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [E=VAR1:$1,L]

Related

Execute php script outside of document root?

I have the following directory structure:
/htdocs
├──test
│ └──.htaccess
└──myphp.php
/htdocs is root for https://example.com and /htdocs/test is root for http://test.example.com
My goal is to execute myphp.php script and pass filename as argument when client requests ./images/* i.e. https://example.com/test/images/blah.png or http://test.example.com/images/blah.png
For this I'm using mod-rewrite in Apache2.4, I have the following in .htaccess:
RewriteEngine On
RewriteRule ^(images/.*)$ ../myphp.php?$1 [L]
This works great with http://example.com/test/images/blah.png, however I'm getting error 400 (bad request) with http://test.example.com/images/blah.png
[2022-05-28 14:36:10] [authz_core:debug] [pid 26880:tid 1888] mod_authz_core.c(815): [client 127.0.0.1:9862] AH01626: authorization result of Require all granted: granted
[2022-05-28 14:36:10] [authz_core:debug] [pid 26880:tid 1888] mod_authz_core.c(815): [client 127.0.0.1:9862] AH01626: authorization result of <RequireAny>: granted
[2022-05-28 14:36:10] [core:error] [pid 26880:tid 1888] [client 127.0.0.1:9862] AH00126: Invalid URI in request 'myfile.php' 'GET /images/blah.png HTTP/1.1'
[2022-05-28 14:36:10] [authz_core:debug] [pid 26880:tid 1896] mod_authz_core.c(815): [client 127.0.0.1:9863] AH01626: authorization result of Require all granted: granted, referer http://test.example.com/images/blah.png
[2022-05-28 14:36:10] [authz_core:debug] [pid 26880:tid 1896] mod_authz_core.c(815): [client 127.0.0.1:9863] AH01626: authorization result of <RequireAny>: granted, referer http://test.example.com/images/blah.png
If I try absolute path in .htaccess:
RewriteRule ^(images/.*)$ /htdocs/myphp.php?$1 [L]
I get error 403 (forbidden):
[2022-05-28 14:39:02] [authz_core:debug] [pid 26880:tid 1908] mod_authz_core.c(815): [client 127.0.0.1:2752] AH01626: authorization result of Require all granted: granted
[2022-05-28 14:39:02] [authz_core:debug] [pid 26880:tid 1908] mod_authz_core.c(815): [client 127.0.0.1:2752] AH01626: authorization result of <RequireAny>: granted
[2022-05-28 14:39:02] [core:error] [pid 26880:tid 1908] (20023)The given path was above the root path: [client 127.0.0.1:2752] AH00127: Cannot map GET /images/blah.png HTTP/1.1 to file
[2022-05-28 14:39:02] [authz_core:debug] [pid 26880:tid 1908] mod_authz_core.c(815): [client 127.0.0.1:2752] AH01626: authorization result of Require all granted: granted, referer http://test.example.com/images/blah.png
[2022-05-28 14:39:02] [authz_core:debug] [pid 26880:tid 1908] mod_authz_core.c(815): [client 127.0.0.1:2752] AH01626: authorization result of <RequireAny>: granted, referer http://test.example.com/images/blah.png
Any suggestions how to make this work if possible without hard-coding domain names?

Debugging Apache2 RewriteRule (with headers)?

So, I've seen Tips for debugging .htaccess rewrite rules - but I have a hard time making use of the suggestions there.
Basically, what I would wish for, is to see what the input and output is of every RewriteCond and RewriteRule entry, as well as the order in which they run, but I cannot seem to find anything that will help me understand that.
So here is a brief example, from what I've read so far: I'm running Apache2 locally on my Windows 10 machine; and I have the following in httpd.conf:
<Location /subfold/dl>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subfold/dl/
RewriteRule ^subfold/dl/(.*)/(.*)$ httpdocs__$1__$2 [ENV=RSLT:AAA,NE]
SetEnvIf Request_URI "^/subfold/dl/" REWRGO=Yes
# "without 'always' your additions will only go out on succesful responses"
Header always set X-REWRGO "%{REWRGO}e"
Header always set X-RSLT "%{RSLT}e"
</Location>
So, here I basically create a wrong rewrite rule, which means the server will always respond with 404.
Because of that, I have to use the always keyword with Header - otherwise response headers never get sent (see Apache: difference between "Header always set" and "Header set"?).
Eventually, what I'd want, is to capture [ENV=RSLT:httpdocs__$1__$2,NE] the output of the rewrite rule in an environment variable, and then write that variable in the response header. Unfortunately, that does not quite work - when I try to issue a request with curl:
$ curl -IkL http://127.0.0.1/subfold/dl/my/test.html
HTTP/1.1 404 Not Found
Date: Mon, 18 Oct 2021 10:29:12 GMT
Server: Apache/2.4.46 (Win32) OpenSSL/1.1.1j
X-REWRGO: Yes
X-RSLT: (null)
Content-Type: text/html; charset=iso-8859-1
... we can see that the REWRGO variable value did end up in the header - but the RSLT is seen as having value null, even if it was explicitly set to value AAA; furthermore, my log settings:
LogLevel notice setenvif:trace8 rewrite:trace8
... print this in Apache2's error.log:
[Mon Oct 18 12:29:12.151566 2021] [rewrite:trace2] [pid 11368:tid 1932] mod_rewrite.c(483): [client 127.0.0.1:9848] 127.0.0.1 - - [127.0.0.1/sid#14c6370][rid#7031e10/initial] init rewrite engine with requested uri /subfold/dl/my/test.html
[Mon Oct 18 12:29:12.152573 2021] [rewrite:trace1] [pid 11368:tid 1932] mod_rewrite.c(483): [client 127.0.0.1:9848] 127.0.0.1 - - [127.0.0.1/sid#14c6370][rid#7031e10/initial] pass through /subfold/dl/my/test.html
[Mon Oct 18 12:29:12.152573 2021] [setenvif:trace2] [pid 11368:tid 1932] mod_setenvif.c(630): [client 127.0.0.1:9848] Setting REWRGO
[Mon Oct 18 12:29:12.152573 2021] [rewrite:trace3] [pid 11368:tid 1932] mod_rewrite.c(483): [client 127.0.0.1:9848] 127.0.0.1 - - [127.0.0.1/sid#14c6370][rid#7031e10/initial] [perdir /subfold/dl/] add path info postfix: C:/bin/Apache24/htdocs/subfold -> C:/bin/Apache24/htdocs/subfold/dl/my/test.html
[Mon Oct 18 12:29:12.152573 2021] [rewrite:trace3] [pid 11368:tid 1932] mod_rewrite.c(483): [client 127.0.0.1:9848] 127.0.0.1 - - [127.0.0.1/sid#14c6370][rid#7031e10/initial] [perdir /subfold/dl/] applying pattern '^subfold/dl/(.*)/(.*)$' to uri 'C:/bin/Apache24/htdocs/subfold/dl/my/test.html'
[Mon Oct 18 12:29:12.153551 2021] [rewrite:trace1] [pid 11368:tid 1932] mod_rewrite.c(483): [client 127.0.0.1:9848] 127.0.0.1 - - [127.0.0.1/sid#14c6370][rid#7031e10/initial] [perdir /subfold/dl/] pass through C:/bin/Apache24/htdocs/subfold
So, I have everything in this log, except what I need - and that is: what was the final URL string that came out of the RewriteRule (wrong or not)?
But, regardless - the error log shows me, at least, that the RewriteRule has been triggered, and that would make me expect that the RSLT environment variable should be set too; but it is not - as we can see in the header, it is null. So cannot really use this technique for debugging, either.
(I guess, this environment variable problem is due to, as noted in RewriteCond with SetEnv , which quotes Setting Environment Variables:
The SetEnv directive runs late during request processing meaning that directives
such as SetEnvIf and RewriteCond will not see the variables set with it.
But then, the same post says setting an environment variable within the RewriteRule should work - and yet, in my example, it does not?)
Can anyone help me with, how can I correctly capture the output of a RewriteRule, and then print it somehow - for instance, as a header value - for each request URL that I might send through, say, curl?
Ok, managed to get a bit further with this.
First, let's consider this httpd.conf snippet:
<Location /subfold/dl>
RewriteEngine On
RewriteOptions AllowAnyURI
RewriteCond %{REQUEST_URI} ^/subfold/dl/
#RewriteRule subfold/dl/(.*)/(.*)$ httpdocs__$1__$2
RewriteRule (.*) - [E=RSLT:$1,CO=;frontdoor;yes_"$1";127.0.0.1;1440;/,NE,PT,L]
SetEnvIf Request_URI "^/subfold/dl/" REWRGO=Yes
# "without 'always' your additions will only go out on succesful responses"
SetEnvIf Cookie "frontdoor=([^;]+)" MyFrontDoor=%1
Header always set X-REWRGO "%{REWRGO}e"
Header always set X-RSLT "%{RSLT}e"
Header always set X-FRONTDOOR "%{MyFrontDoor}e"
Header always set X-Request_URI1 "%{REQUEST_URI}e"
Header always set X-Request_URI2 "expr=%{REQUEST_URI}"
</Location>
When I have this in my httpd.conf, and I start Apache httpd.exe, and I issue a request, this is what I get now:
$ curl -IkL http://127.0.0.1/subfold/dl/my/test.html
HTTP/1.1 404 Not Found
Date: Mon, 18 Oct 2021 12:35:36 GMT
Server: Apache/2.4.46 (Win32) OpenSSL/1.1.1j
X-REWRGO: Yes
X-RSLT: C:/bin/Apache24/htdocs/subfold/dl/my/test.html
X-FRONTDOOR: (null)
X-Request_URI1: (null)
X-Request_URI2: /subfold/dl/my/test.html
Set-Cookie: frontdoor=yes_"C:/bin/Apache24/htdocs/subfold/dl/my/test.html"; path=/; domain=127.0.0.1; expires=Tue, 19-Oct-2021 12:35:36 GMT
Content-Type: text/html; charset=iso-8859-1
So, something started working ... and what I gather from this:
First, the AllowAnyURI is not really needed here - I thought it was because https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html says:
When RewriteRule is used in VirtualHost or server context with version 2.2.22 or later of httpd, mod_rewrite will only process the rewrite rules if the request URI is a URL-path.
I was afraid that my request URI might not be recognized, so I enabled AllowAnyURI - but that does not seem to be the issue here.
So here is what this tests: with RewriteRule (.*) - we basically have a "passthrough" - the original request does not get rewritten; again https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html :
The Substitution may be a: ...
- (dash)
A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.
... and we also have the corresponding [PT] flag there. Then, since the entire match request is in parentheses (.*) and therefore captured, we can output it with $1 in the same line; and finally, we both set an environment variable RSLT to this, as well as a cookie.
Now here is where I got surprised: what ends up in the "Pattern" part of the rewrite rule is not the original URL - it is what Apache would see as the translation of this URL to the local filesystem!!!
I first noticed this, when I got split values for the cookie, as it always splits on colons (:) - even if it is string data in a variable (which however did contain C:/.., which is what end up being split)! Hence I tried to use double quotes, but that did not work - what worked eventually was https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_co :
If a literal ':' character is needed in any of the cookie fields, an alternate syntax is available. To opt-in to the alternate syntax, the cookie "Name" should be preceded with a ';' character, and field separators should be specified as ';'.
In any case, here we've had:
http://127.0.0.1 /subfold/dl/my/test.html - original request
C:/bin/Apache24/htdocs /subfold/dl/my/test.html - what Apache mapped that request to, in the local filesystem
And essentially, this was the problem with the code in the OP: RewriteRule ^subfold/dl/(.*)/(.*)$ ... would mean: replace the string that starts with subfold... - however, the string ``C:/bin/...` definitely does not start like that, and so the RewriteRule never matches, and does not execute!
I guess, another confusion for me was, that (.*) as the Pattern (first arg) in RewriteRule, typically looks like the REQUEST_URI - but that is within .htaccess in a directory; https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html again:
In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). This is the (%-decoded) URL-path.
In per-directory context (Directory and .htaccess), the Pattern is matched against only a partial path, for example a request of "/app1/index.html" may result in comparison against "app1/index.html" or "index.html" depending on where the RewriteRule is defined.
... where
REQUEST_URI
The path component of the requested URI, such as "/index.html". This notably excludes the query string which is available as its own variable named QUERY_STRING
So, my bad was, that I was assuming (.*) as Pattern in the RewriteRule would be matched to the path component (REQUEST_URI-like) and I attempted matching versus that; whereas, in this case, it was actually the full filesystem path, starting with C:/...!
The being said, we can now uncomment the line RewriteRule subfold/dl/(.*)/(.*)$ httpdocs__$1__$2 in the above snippet - realising that this time, the match does not have the starting caret (^), which would means "match the start of string":
<Location /subfold/dl>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subfold/dl/
RewriteRule subfold/dl/(.*)/(.*)$ httpdocs__$1__$2
RewriteRule (.*) - [E=RSLT:$1,CO=;frontdoor;yes_"$1";127.0.0.1;1440;/,NE,PT,L]
SetEnvIf Request_URI "^/subfold/dl/" REWRGO=Yes
# "without 'always' your additions will only go out on succesful responses"
SetEnvIf Cookie "frontdoor=([^;]+)" MyFrontDoor=%1
Header always set X-REWRGO "%{REWRGO}e"
Header always set X-RSLT "%{RSLT}e"
Header always set X-FRONTDOOR "%{MyFrontDoor}e"
Header always set X-Request_URI1 "%{REQUEST_URI}e"
Header always set X-Request_URI2 "expr=%{REQUEST_URI}"
</Location>
... and the response to this is:
$ curl -IkL http://127.0.0.1/subfold/dl/my/test.html
HTTP/1.1 404 Not Found
Date: Mon, 18 Oct 2021 13:18:33 GMT
Server: Apache/2.4.46 (Win32) OpenSSL/1.1.1j
X-REWRGO: Yes
X-RSLT: C:/bin/Apache24/htdocs/subfold/dl/httpdocs__my__test.html
X-FRONTDOOR: (null)
X-Request_URI1: (null)
X-Request_URI2: /subfold/dl/httpdocs__my__test.html
Set-Cookie: frontdoor=yes_"httpdocs__my__test.html/dl/my/test.html"; path=/; domain=127.0.0.1; expires=Tue, 19-Oct-2021 13:18:33 GMT
Content-Type: text/html; charset=iso-8859-1
So, yeah - finally I can see the expected mod_rewrite string substitution/replacement in headers, even if the rewritten URI is incorrect (i.e. does not correctly map to existing local filesystem data) -- which is what I wanted to achieve.
For fun, this is what comes out of the Apache error (that is, mod_rewrite) log:
[Mon Oct 18 15:21:55.007369 2021] [rewrite:trace2] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] init rewrite engine with requested uri /subfold/dl/my/test.html
[Mon Oct 18 15:21:55.007369 2021] [rewrite:trace1] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] pass through /subfold/dl/my/test.html
[Mon Oct 18 15:21:55.008369 2021] [setenvif:trace2] [pid 15508:tid 1936] mod_setenvif.c(630): [client 127.0.0.1:12206] Setting REWRGO
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] add path info postfix: C:/bin/Apache24/htdocs/subfold -> C:/bin/Apache24/htdocs/subfold/dl/my/test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] applying pattern 'subfold/dl/(.*)/(.*)$' to uri 'C:/bin/Apache24/htdocs/subfold/dl/my/test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace4] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] RewriteCond: input='/subfold/dl/my/test.html' pattern='^/subfold/dl/' => matched
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace2] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] rewrite 'C:/bin/Apache24/htdocs/subfold/dl/my/test.html' -> 'httpdocs__my__test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] add per-dir prefix: httpdocs__my__test.html -> /subfold/dl/httpdocs__my__test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] add path info postfix: /subfold/dl/httpdocs__my__test.html -> /subfold/dl/httpdocs__my__test.html/dl/my/test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] strip per-dir prefix: /subfold/dl/httpdocs__my__test.html/dl/my/test.html -> httpdocs__my__test.html/dl/my/test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] applying pattern '(.*)' to uri 'httpdocs__my__test.html/dl/my/test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace5] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] setting env variable 'RSLT' to 'httpdocs__my__test.html/dl/my/test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace5] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] setting cookie 'frontdoor=yes_"httpdocs__my__test.html/dl/my/test.html"; path=/; domain=127.0.0.1; expires=Tue, 19-Oct-2021 13:21:55 GMT'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace2] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] forcing '/subfold/dl/httpdocs__my__test.html' to get passed through to next API URI-to-filename handler
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace2] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] trying to replace context docroot C:/bin/Apache24/htdocs with context prefix
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace1] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b22d90/initial] [perdir /subfold/dl/] internal redirect with /subfold/dl/httpdocs__my__test.html [INTERNAL REDIRECT]
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace2] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] init rewrite engine with requested uri /subfold/dl/httpdocs__my__test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace1] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] pass through /subfold/dl/httpdocs__my__test.html
[Mon Oct 18 15:21:55.008369 2021] [setenvif:trace2] [pid 15508:tid 1936] mod_setenvif.c(630): [client 127.0.0.1:12206] Setting REWRGO
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] [perdir /subfold/dl/] add path info postfix: C:/bin/Apache24/htdocs/subfold -> C:/bin/Apache24/htdocs/subfold/dl/httpdocs__my__test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] [perdir /subfold/dl/] applying pattern 'subfold/dl/(.*)/(.*)$' to uri 'C:/bin/Apache24/htdocs/subfold/dl/httpdocs__my__test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] [perdir /subfold/dl/] add path info postfix: C:/bin/Apache24/htdocs/subfold -> C:/bin/Apache24/htdocs/subfold/dl/httpdocs__my__test.html
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace3] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] [perdir /subfold/dl/] applying pattern '(.*)' to uri 'C:/bin/Apache24/htdocs/subfold/dl/httpdocs__my__test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace5] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] setting env variable 'RSLT' to 'C:/bin/Apache24/htdocs/subfold/dl/httpdocs__my__test.html'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace5] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] skipping already set cookie 'frontdoor'
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace2] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] [perdir /subfold/dl/] forcing 'C:/bin/Apache24/htdocs/subfold' to get passed through to next API URI-to-filename handler
[Mon Oct 18 15:21:55.008369 2021] [rewrite:trace1] [pid 15508:tid 1936] mod_rewrite.c(483): [client 127.0.0.1:12206] 127.0.0.1 - - [127.0.0.1/sid#f88ee0][rid#6b1a020/initial/redir#1] [perdir /subfold/dl/] initial URL equal rewritten URL: C:/bin/Apache24/htdocs/subfold [IGNORING REWRITE]
Finally, note:
Now that our RewriteRule does not insist on ^start of string, the cookie value does not contain the starting part of the absolute path as before
However, we still have the absolute local (C:/...) path for RSLT - and that persist, even if we add [P] (for proxy) or [R=302] (for redirect) flags to the RewriteRule (there will be no change in behavior, since the page regardless returns 404)
For some reason, SetEnvIf Cookie doesn't match the cookie, even if the cookie get written out
Even if %{REQUEST_URI} definitely exists, it does not get output in header via the "%{REQUEST_URI}e" syntax - it only gets output via the "expr=%{REQUEST_URI}" syntax, which I guess is an ap_expr

Prestashop v1.4.8.2 images missing after upgrade to v1.6.0 and rollback

I'm new to prestashop.
Yesterday I upgraded my prestashop dashboard with "1-click Upgrade" module from version 1.4.8.2 to 1.6.0 stable. After the upgrade the whole website template was changed and some images were missing, so i decided to rollback the versions. At first it seemed everything was OK, but today I noticed some images on the site are missing/or I might have wrong URL's to the images (I don't know how it was before).
I also did backups of database and website. I checked the URL of a missing image and it doesn't exist even in the backup folder. Any idea what is going on?
Here is an example of error i get in the browser:
"GET http://{mywebsite}.com/img/c/sl-default-medium.jpg 404 (Not
Found)"
EDIT:
I tried to run image regeneration and this error was returned:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your >request.
Please contact the server administrator, webmaster#{mywebsite}.com and inform them of the time the >error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
EDIT2:
300 latest error logs from cpanel:
[Thu Nov 27 03:21:20 2014] [error] [client 164.8.7.90] File does not
exist: /home/papirtar/public_html/img/p/sl-default-medium.jpg,
referer: http://papirnicatara.com/product.php?id_product=185 [Thu Nov
27 03:13:53 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/7, referer:
http://papirnicatara.com/category.php?id_category=10 [Thu Nov 27
03:13:53 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/7, referer:
http://papirnicatara.com/category.php?id_category=10 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/7, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/4/6, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/7, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/3/5, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:43 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/3/5, referer:
http://papirnicatara.com/category.php?id_category=8 [Thu Nov 27
03:13:28 2014] [error] [client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/
[Thu Nov 27 03:13:28 2014] [error] [client 109.182.65.7] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:13:28 2014] [error] [client
109.182.65.7] File does not exist: /home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/ [Thu Nov 27 03:13:28 2014] [error]
[client 109.182.65.7] File does not exist:
/home/papirtar/public_html/img/p/7, referer: http://papirnicatara.com/
[Thu Nov 27 03:13:14 2014] [error] [client 164.8.7.90] File does not
exist: /home/papirtar/public_html/favicon.ico [Thu Nov 27 03:10:47
2014] [error] [client 66.249.64.109] File does not exist:
/home/papirtar/public_html/img/p/4/4/3 [Thu Nov 27 03:10:41 2014]
[error] [client 66.249.64.101] File does not exist:
/home/papirtar/public_html/img/p/4/2/1 [Thu Nov 27 03:09:32 2014]
[error] [client 164.8.7.90] File does not exist:
/home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/
[Thu Nov 27 03:09:32 2014] [error] [client 164.8.7.90] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:09:32 2014] [error] [client
164.8.7.90] File does not exist: /home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/ [Thu Nov 27 03:09:32 2014] [error]
[client 164.8.7.90] File does not exist:
/home/papirtar/public_html/img/p/7, referer: http://papirnicatara.com/
[Thu Nov 27 03:08:18 2014] [error] [client 164.8.7.90] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:08:18 2014] [error] [client
164.8.7.90] File does not exist: /home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/ [Thu Nov 27 03:08:18 2014] [error]
[client 164.8.7.90] File does not exist:
/home/papirtar/public_html/img/p/7, referer: http://papirnicatara.com/
[Thu Nov 27 03:08:18 2014] [error] [client 164.8.7.90] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:06:33 2014] [error] [client
164.8.161.54] File does not exist: /home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/ [Thu Nov 27 03:06:33 2014] [error]
[client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/
[Thu Nov 27 03:06:33 2014] [error] [client 164.8.161.54] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:06:33 2014] [error] [client
164.8.161.54] File does not exist: /home/papirtar/public_html/img/p/7, referer: http://papirnicatara.com/ [Thu Nov 27 03:06:30 2014] [error]
[client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/5, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/5, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/5, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/5, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/5, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/5, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/4/8, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/4/9, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/4/8, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/4/6, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/c/sl-default-medium.jpg, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/sl-default-medium.jpg, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:30 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/4/7, referer:
http://papirnicatara.com/category.php?id_category=2 [Thu Nov 27
03:06:27 2014] [error] [client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/
[Thu Nov 27 03:06:27 2014] [error] [client 164.8.161.54] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:06:27 2014] [error] [client
164.8.161.54] File does not exist: /home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/ [Thu Nov 27 03:06:27 2014] [error]
[client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/7, referer: http://papirnicatara.com/
[Thu Nov 27 03:06:23 2014] [error] [client 164.8.161.54] File does not
exist: /home/papirtar/public_html/img/p/8, referer:
http://papirnicatara.com/ [Thu Nov 27 03:06:23 2014] [error] [client
164.8.161.54] File does not exist: /home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/ [Thu Nov 27 03:06:22 2014] [error]
[client 164.8.161.54] File does not exist:
/home/papirtar/public_html/img/p/8, referer: http://papirnicatara.com/
[Thu Nov 27 03:06:22 2014] [error] [client 164.8.161.54] File does not
exist: /home/papirtar/public_html/img/p/7, referer:
http://papirnicatara.com/

Apache - caching responses from app server

I have an web application server sitting behind Apache 2.4.2 in a reverse proxy configuration. The app server returns a response including the following headers:
Pragma: no-cache
Vary: Accept-Encoding
Cache-Control: no-cache
Expires: Mon, 07 Jan 2013 01:21:30 GMT
I have Apache 2.4.2 working as a reverse proxy in front of this application server and want to cache responses from the application server. I can't modify the application server. How do I do this in Apache? I was hopeful for CacheStoreExpired and CacheIgnoreCacheControl but they don't help here because Apache makes a conditional request to the backend - and the app server always wants to refresh the cache with something new that expires 'now'. I wonder if I can rewrite the headers returned from the application server?
I am using mod_cache (to no avail) with this config:
CacheEnable disk /
CacheRoot "C:/Program Files/Apache Software Foundation/Apache2.4/cache/"
CacheIgnoreCacheControl On
CacheIgnoreNoLastMod On
CacheStoreNoStore On
CacheStoreExpired On
CacheStaleOnError on
LogLevel debug
CacheHeader on
CacheDetailHeader on
CacheDefaultExpire 120
CacheMaxExpire 120
SetEnv proxy-nokeepalive 1
ProxyPass / http://localhost:8080/
Apache's debug log is a bit worrying, too:
[Fri Jan 04 16:27:52.113857 2013] [cache:debug] [pid 2824:tid 964] cache_storage.c(624): [client 192.168.4.36:51783] AH00698: cache: Key for entity /browse?(null) is http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:52.113857 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(159): [client 192.168.4.36:51783] AH00750: Adding CACHE_SAVE filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:52.113857 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(169): [client 192.168.4.36:51783] AH00751: Adding CACHE_REMOVE_URL filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.503049 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1190): [client 192.168.4.36:51783] AH00769: cache: Caching url: /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.503049 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1196): [client 192.168.4.36:51783] AH00770: cache: Removing CACHE_REMOVE_URL filter., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.643529 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(1318): [client 192.168.4.36:51783] AH00737: commit_entity: Headers and body for URL http://192.168.4.189:80/browse? cached., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] cache_storage.c(624): [client 192.168.4.36:51783] AH00698: cache: Key for entity /browse?(null) is http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(569): [client 192.168.4.36:51783] AH00709: Recalled cached URL info header http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(865): [client 192.168.4.36:51783] AH00720: Recalled headers for URL http://192.168.4.189:80/browse?, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] cache_storage.c(320): [client 192.168.4.36:51783] AH00695: Cached response for /browse isn't fresh. Adding/replacing conditional request headers., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(159): [client 192.168.4.36:51783] AH00750: Adding CACHE_SAVE filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:53.799618 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(169): [client 192.168.4.36:51783] AH00751: Adding CACHE_REMOVE_URL filter for /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.235637 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1190): [client 192.168.4.36:51783] AH00769: cache: Caching url: /browse, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.235637 2013] [cache:debug] [pid 2824:tid 964] mod_cache.c(1196): [client 192.168.4.36:51783] AH00770: cache: Removing CACHE_REMOVE_URL filter., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:warn] [pid 2824:tid 964] (OS 5)Access is denied. : [client 192.168.4.36:51783] AH00699: rename tempfile to file failed: C:/Program Files/Apache Software Foundation/Apache2.4/cache/aptmpcJvfPV -> C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3/xM0hz_t8XPQaojszgaGA.data, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(617): [client 192.168.4.36:51783] AH00711: Deleting C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3/xM0hz_t8XPQaojszgaGA.header from cache., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(634): [client 192.168.4.36:51783] AH00713: Deleting C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3/xM0hz_t8XPQaojszgaGA.data from cache., referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(674): [client 192.168.4.36:51783] AH00715: Deleting directory C:/Program Files/Apache Software Foundation/Apache2.4/cache/A/3 from cache, referer: http://192.168.4.189/browse
[Fri Jan 04 16:27:55.298072 2013] [cache_disk:debug] [pid 2824:tid 964] mod_cache_disk.c(1313): [client 192.168.4.36:51783] AH00736: commit_entity: URL 'http://192.168.4.189:80/browse?' not cached due to earlier disk error., referer: http://192.168.4.189/browse
You can do this with mod_cache
http://httpd.apache.org/docs/current/mod/mod_cache.html
Please consider also to add:
CacheIgnoreQueryString On
Requests with query string parameters are not cached by default.
Looking at your log, there is an error in the last line: not cached due to earlier disk error.
May be your apache server does not have correct permission to write into cache directory, or your disk is full...
You should double check if the apache memcache directory is correctly created.
You can use CacheIgnoreHeaders to ignore unwanted headers from the backend app server:
http://httpd.apache.org/docs/current/mod/mod_cache.html#cacheignoreheaders
For example:
CacheIgnoreHeaders Set-Cookie Cookie Cookie2 X-Forwarded-For X-Forwarded-Host

Apache with Eruby not parsing require statement properly

I recently configured Apache with eruby and got some rhtml pages running. I have a globalfunctions.rb file that I want to be available to all of the pages that I have running on the site.
However, I have a problem: putting a require statement in rhtml makes it break and return error 500. Here's the code for the page:
<html>
<head>
<title>Home | Quantum Software</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<%
require './globalfunctions.rb'
%>
<div class="contentBox">
</div>
</body>
</html>
And the global functions file:
def get_file_name()
return File.basename(__FILE__)
end
def new_nav_link( target, title )
currentFileName = get_file_name()
if target == currentFileName
puts %Q##{title}#
else
puts %Q##{title}#
end
end
And lastly, here's the last few lines of error.log:
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] :
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] no such file to load -- ./globalfunctions.rb
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] (
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] LoadError
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] )
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] --- generated code ---
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<html>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<head>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\t<title>Home | Quantum Software</title>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\t<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"style.css\\" />\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</head>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<body>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103]
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] require "./globalfunctions.rb"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<div class=\\"contentBox\\">\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</div>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</body>\\n"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</html>"
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] ----------------------
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] Premature end of script headers: eruby
[Fri Apr 27 23:23:24 2012] [error] an unknown filter was not added: includes
[Fri Apr 27 23:23:24 2012] [error] an unknown filter was not added: includes
[Fri Apr 27 23:24:04 2012] [error] an unknown filter was not added: includes
[Fri Apr 27 23:27:03 2012] [error] an unknown filter was not added: includes
Thanks for your help in advance.
Print out $LOAD_PATH and Dir.pwd inside your rhtml file:
<!-- For example like this -->
<p>
The load path is: <br />
<%= $LOAD_PATH.join("<br />\n") %>
</p>
<p>
The current working directory is: <%= Dir.pwd %>
</p>
You will probably find that the current working directory (Dir.pwd) of the Ruby interpreter is not the same as the location of your rhtml file. So Ruby cannot find globalfunctions because it only looks for it in $LOAD_PATH.
In that case you need to require your file with an absolute path, like:
require '/var/www/mypages/globalfuntions'
OR alternatively place your globalfuntions.rb either in any directory that $LOAD_PATH points to, or into the place that Dir.pwd points to (the current working directory of the Ruby interpreter).

Resources