why does this condition match

Discuss practical ways rearrange URLs using mod_rewrite.

why does this condition match

Postby mboedick » Tue Sep 14, 2004 10:52 am

I have the following in my .htaccess file:

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

When I request "/test/foo" and the file "/test.html" exists, I get an internal server error. It should be giving me a 404.

Why does the rewrite condition evaluate true? The directory "/test" does not exist and the file "/test/foo.html" does not exist, so the -f should return false. It seems like mod_rewrite is appending .html to just the "test" part of the path and testing that.

Any ideas?
mboedick
 
Posts: 1
Joined: Tue Sep 14, 2004 10:45 am

Postby seomike » Tue Sep 14, 2004 12:09 pm

RewriteCond %{REQUEST_URI} !-d
RewriteRule ^(.*)/.*$ /$1.html [R]


if the directory is called /test/foo and it doesn't exist then the the rewrite rule will redirect to a file on the root of the server called /test.html.

If you don't want it to redirect the change the [R] to [L] and it will read the file test.html as if it were /test/foo
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 56 guests

cron