Forum Moderators: phranque

Message Too Old, No Replies

Need Help w/ RewriteCond

RewriteCond /example/%{REQUEST_FILENAME} -f always fails

         

darkzerox

8:33 am on Jun 30, 2008 (gmt 0)

10+ Year Member



Just can't figure out why this doesn't want to work:

RewriteEngine on

RewriteCond /exampledirectory/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /exampledirectory/$1 [L]

Then when I try to access my site at example.com/about.php for example, and example.com/exampledirectory/about.php exists, I get a 404 error. When I comment out the RewriteCond it works perfectly though.

What might be causing this problem? Thanks!

jdMorgan

2:13 pm on Jun 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



{REQUEST_FILENAME) will contain the full filesystem path to the file that the client request currently resolves to, so it's likely that this RewriteCond is not testing the right path.

Looking at what you've got, and using an typical example value for DOCUMENT_ROOT of "/users/example/www/html" and a requested URL of "example.com/about.php", the path examined by your RewriteCond would be "/exampledirectory//users/example/www/html/about.php"

You might try using


RewriteCond %{DOCUMENT_ROOT}/exampledirectory%{REQUEST_URI}
instead.

If necessary, you could make a test rule to 'expose' your values in your browser's address bar, so you can see them. For example:


RewriteCond $1 !^exampledirectory/
RewriteRule ^(.+)$ /exampledirectory/$1?the-tested-filepath-was=/exampledirectory/%{REQUEST_FILENAME} [R=302,L]

This is only for testing!

Jim

darkzerox

7:17 pm on Jun 30, 2008 (gmt 0)

10+ Year Member



Aha! You're a genius! I couldn't figure out how to test my rewrite rule, so I wasn't quite sure what was wrong. This works great, thank you!