Forum Moderators: phranque
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.
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.
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
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.