Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Guide Incorrect?

         

deizu

8:31 pm on Apr 12, 2005 (gmt 0)

10+ Year Member




Description:

Sometimes it is necessary to let the webserver search for pages in more than one directory. Here MultiViews or other techniques cannot help.
Solution:

We program a explicit ruleset which searches for the files in the directories.

RewriteEngine on

# first try to find it in custom/...
# ...and if found stop and be happy:
RewriteCond /your/docroot/dir1/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir1/$1 [L]

# second try to find it in pub/...
# ...and if found stop and be happy:
RewriteCond /your/docroot/dir2/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir2/$1 [L]

# else go on for other Alias or ScriptAlias directives,
# etc.
RewriteRule ^(.+) - [PT]

I'm currently learning rewriting and I periodically go through more of the guide. However, the snippet doesn't seem to be accurate.

Could someone confirm this please. I realize that it is possible that I have missed something so I wanted to check if I have.

I was however, able to accomplish the task but not as it is shown in the guide.

Btw, as far as I know this is a rewrite rule for the apache config file.

Thanks in advance.

deizu

8:42 pm on Apr 12, 2005 (gmt 0)

10+ Year Member



To add, The issue is the %{REQUEST_FILENAME}.

Since it holds the URI the rewrite would only be valid for a filename request in the docroot. Which isn't what I believe this is suppose to be doing

ie a request for /path/to/file.htm wouldn't find file.htm in dir1 or dir2 because it'll be looking for the files in /dir1/path/to/file.htm or /dir2/path/to/file.htm.

jdMorgan

1:08 am on Apr 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As long as the paths in the RewriteCond and the RewriteRule are the same, this should work.

The purpose is to allow 'your/docroot/dir[12]' to assume any value. The resource file will be located in either
your/docroot/dir1 or your/docroot/dir2, but will appear to be in the home directory of the site. You could also add code to make it appear to be in any subdirectory your like by stripping that subdirectory path off the requested URI before performing the 'file exists' test.

Jim

deizu

12:40 am on Apr 14, 2005 (gmt 0)

10+ Year Member




You could also add code to make it appear to be in any subdirectory your like by stripping that subdirectory path off the requested URI before performing the 'file exists' test.

I may have jumped the gun when I assumed that it was trying to do that from the start, but I see that it could have actually been deliberate to have it only deal with making files appear to be located in the home directory.