httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kynn Jones <kyn...@gmail.com>
Subject [users@httpd] beginner's mod_rewrite recursion problem
Date Tue, 05 May 2009 15:02:45 GMT
I'm new to mod_rewrite, and need advice on whether what i want to do is
possible.  I have a physical structure analogous to the following:
/path/to/docroot/foo/bar/index.html
/path/to/docroot/foo/css
/path/to/docroot/foo/images

/path/to/docroot/frobozz/css
/path/to/docroot/frobozz/images

I want that when a user points the browser to http://myserver/frobozz/, the
server internally maps that request to the file
/path/to/docroot/foo/bar/index.html, but if the browser is pointed to
http://myserver/frobozz/css/somefile.css, the retrieved file will be the one
at /path/to/docroot/frobozz/css/somefile.css.

I thought I could solve the problem by putting this in the
file /path/to/docroot/.htaccess:

RewriteEngine on
RewriteBase /

RewriteRule ^foo/?$ bar/html/index.html [L]


This almost worked: pointing the browser to http://myserver/frobozz/ caused
the page at /path/to/docroot/foo/bar/index.html to be served, while pointing
the browser to http://myserver/frobozz/css/somefile.css still gave me the
document at /path/to/docroot/frobozz/css/somefile.css.

The problem is that the file at /path/to/docroot/foo/bar/index.html requires
other local files with directives like:

<img src='../images/arrow.gif'/>

...and these requests fail with error messages like "File does not exist:
/path/to/docroot/images, referer: http://myserver/frobozz/".

What appears that is happening is that the '../images/arrow.gif' is being
interpreted as 'http://myserver/frobozz/../images/arrow.gif' and not as '
http://myserver/foo/bar/../images/arrow.gif'.

I tried to fix this by adding the following rule at the end
of /path/to/docroot/.htaccess:

RewriteCond %{HTTP_REFERER} ^http://myserver/frobozz/?$
RewriteRule ^(.*) foo$1

...but this causes a recursion error: "Request exceeded the limit of 10
internal redirects...".


Any advice would be greatly appreciated!

In particular, what's the best way to inspect the values of the various
variables that are available for the TestString in RewriteCond, including
the special ones like THE_REQUEST and IS_SUBREQ?

TIA!

Kynn

Mime
View raw message