Page 1 of 1

mod_rewrite weirdness

Posted: Wed Feb 13, 2008 7:05 pm
by RobertGonzalez
Sorry for the abstract title. I cannot think of a better way to title this question.

Can anyone tell me why the first ruleset here does not work but the second one does?

Code: Select all

##
# THIS RULESET FAILS
##
# If the requested filename is not an existing file
RewriteCond %{REQUEST_FILENAME} !-f [OR]
 
# If the requested is not an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
 
# Pump the entire request through the bootstrap file
RewriteRule ^(.*)$ index.php [QSA,L]

Code: Select all

##
# THIS RULESET WORKS
##
# If the requested filename is an existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
 
# If the requested filename is a directory
RewriteCond %{REQUEST_FILENAME} -d
 
# Use the request as is and skip the following 1 rewrite rules
RewriteRule ^.*$ - [S=1]
 
# Pump the entire request through the bootstrap file
RewriteRule ^(.*)$ index.php [QSA,L]
In the first rule set, a call to a directory like http://mylocalhost/Dirthatexists/ tries to push this request through the index.php bootstrap file instead of serving the index.html file that is in the directory. The second rule set works exactly as expected, serving up index.html from the Dirthatexists/ directory.

Wouldn't you think the first ruleset should work?

PS I do have the rewrite engine on, in case that comes up.

Re: mod_rewrite weirdness

Posted: Fri Feb 15, 2008 12:08 am
by Benjamin
Where can I read about [OR]? What does that do? The rest looks fine to me. Maybe the [OR] is adding some wackyness.

Re: mod_rewrite weirdness

Posted: Fri Feb 15, 2008 10:29 am
by RobertGonzalez
astions wrote:Where can I read about [OR]? What does that do? The rest looks fine to me. Maybe the [OR] is adding some wackyness.
[OR] is listed as #3 in the section just above the example on this page.

Re: mod_rewrite weirdness

Posted: Fri Feb 15, 2008 12:06 pm
by Benjamin
That is strange Everah. I have a similiar set of rules that work perfectly.

Re: mod_rewrite weirdness

Posted: Fri Feb 15, 2008 1:04 pm
by John Cartwright
Weird. Looks good to me :banghead:

//step in guru

Re: mod_rewrite weirdness

Posted: Fri Feb 15, 2008 1:55 pm
by inghamn
In your first case, you probably want to leave off the [OR]. And let the implicit AND take over. since you're really only wanting to pump through the bootstrap when It's not a file AND it's not a directory.

Switching to the positives, you would use OR. If it's a file OR it's a directory then don't pass it to the bootstrap