This is a discussion on mod_rewrite for users in / within the Apache Web Server forums, part of the Web Server and Related Forums category; For the last few years, we have had our users on one server and main web site on another. This ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
For the last few years, we have had our users on one server and main
web site on another. This means that the users have all had URIs of the form http://server/user/ as their home pages (userdirs are not in use); the main web site has had URIs of the equivalent form http://server/dir/. We are now amalgamating the servers, and need all the following URIs to work: http://server/index.html http://server/ http://server/dir/index.php http://server/dir/ http://server/user/index.shtml http://server/user/ Since there are so many users, we are trying to keep them out of the main web root, and I had an arrangement like this: /path/to/web/www/ /path/to/web/homepages/ which I was hoping to rewrite with the following lines: RewriteCond %{REQUEST_URI} !-U RewriteRule ^/(.+) /homepages/$1 .... which is failing. I have tried reversing the logic, but the log I have seems to indicate that it's failing completely. I then tried doing it with the recipe from the Apache site: RewriteCond /homepages%{REQUEST_FILENAME} -f RewriteRule ^/(.+) /homepages/$1 [L,NS] RewriteRule ^(.+) - [PT] Which works for files like index.html, but not for requests of the form http://server/dir/. Has anyone got this working or done somthing similar? Thanks, Iain. |
|
|||
|
nineworlds@gmail.com wrote:
> /path/to/web/www/ > /path/to/web/homepages/ which I was hoping to rewrite with the > following lines: [...] > RewriteCond /homepages%{REQUEST_FILENAME} -f # you need a full physical filesystem path, RewriteCond /path/to/web/homepages%{REQUEST_FILENAME} -f # skipping subrequests might cause unexpected results by e.g. # mod_include and include virtual RewriteRule ^/(.+) /homepages/$1 [L,NS] # if a rule dod not match, no uri-to-filename translation # took place, so the following rule should be redundant #RewriteRule ^(.+) - [PT] Post/upload your rewrite.log (with RewriteLogLevel 5) somewhere if you still have problems. -- Robert |
|
|||
|
Thanks.
Again, that works with named files, like index.html, but doesn't work with requests that are directory names (http://server/dir/ or http://server/user/). Here's what's in the conf (inside a virtualhost): RewriteEngine On RewriteLog "/opt/www/apache/logs/rewrite.log" RewriteLogLevel 5 RewriteCond /opt/www/dev/homepages%{REQUEST_FILENAME} -f RewriteRule ^(.+) /homepages$1 [L] And the resulting log: IP - - [11/May/2006:10:54:55 +0100] [dev/sid#de538][rid#1db378/initial] (2) init rewrite engine with requested uri /user/ IP - - [11/May/2006:10:54:55 +0100] [dev/sid#de538][rid#1db378/initial] (3) applying pattern '^(.+)' to uri '/user/' IP - - [11/May/2006:10:54:55 +0100] [dev/sid#de538][rid#1db378/initial] (4) RewriteCond: input='/opt/www/dev/homepages/user/' pattern='-f' => not-matched IP - - [11/May/2006:10:54:55 +0100] [dev/sid#de538][rid#1db378/initial] (1) pass through /user/ Then it tries for the 404 page. With a specified file: IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (2) init rewrite engine with requested uri /user/index.html IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (3) applying pattern '^(.+)' to uri '/user/index.html' IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (4) RewriteCond: input='/opt/www/dev/homepages/user/index.html' pattern='-f' => matched IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (2) rewrite /user/index.html -> /homepages/user/index.html IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (2) local path result: /homepages/user/index.html IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (2) prefixed with document_root to /opt/www/dev/homepages/user/index.html IP - - [11/May/2006:10:55:26 +0100] [dev/sid#de538][rid#1e73a8/initial] (1) go-ahead with /opt/www/dev/homepages/user/index.html [OK] So that worked. Do I need to do some resolving of requests for directories into files first? - Iain. |
|
|||
|
nineworlds@gmail.com wrote:
> RewriteCond /opt/www/dev/homepages%{REQUEST_FILENAME} -f Ah yes, You're checking only for an existing file. Now when you're requesting a directory, the condition would fail, of course. To check also for an existing directory, use RewriteCond /opt/www/dev/homepages%{REQUEST_FILENAME} -f [OR] RewriteCond /opt/www/dev/homepages%{REQUEST_FILENAME} -d -- Robert |