RewriteCond if exact file exists?

Oh, the strange things mod_rewrite does!

RewriteCond if exact file exists?

Postby richcon » Tue Sep 08, 2009 2:51 pm

I have the following in my htaccess file, to launch index.php for all requests where a matching file is not found:

Code: Select all
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

RewriteRule .* index.php [L]


This fails with partial names. Say the following file exists on the server:

/foo/bar.jpg

And the user goes to the following URL:

/foo/bar/

The first rule above triggers (mod_rewrite thinks the file exists), and index.php is never run. Instead, the user gets a stock 404 Not Found error.

This only happens if the extension .x on the bar.x file is a known file type. If the file were /foo/bar.xxx, control passes correctly to my PHP app.

Any idea what's going on here, and how I can instruct mod_rewrite to be more specific in its checks?[/code]
richcon
 
Posts: 2
Joined: Tue Sep 08, 2009 2:38 pm

Postby richardk » Tue Sep 08, 2009 4:11 pm

It sounds like MultiViews, try adding
Code: Select all
Options -MultiViews
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thanks!

Postby richcon » Tue Sep 08, 2009 9:04 pm

That did it! It's operating normally now.

I had a hunch it had something to do with content negotiation, but after skimming through Apache's docs and my httpd.conf file, I couldn't find anything that would explain it.
richcon
 
Posts: 2
Joined: Tue Sep 08, 2009 2:38 pm


Return to Idiosyncrasies

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron