mod_rewrite weirdness

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

mod_rewrite weirdness

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: mod_rewrite weirdness

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: mod_rewrite weirdness

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: mod_rewrite weirdness

Post by Benjamin »

That is strange Everah. I have a similiar set of rules that work perfectly.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: mod_rewrite weirdness

Post by John Cartwright »

Weird. Looks good to me :banghead:

//step in guru
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: mod_rewrite weirdness

Post 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
Post Reply