Error 404 when URL to be rewritten matches filename AND case

Oh, the strange things mod_rewrite does!

Error 404 when URL to be rewritten matches filename AND case

Postby zendak » Tue May 02, 2006 12:58 pm

I've created some very simple rewrite rules:
Code: Select all
RewriteEngine On
RewriteRule ^aboutus/?$ aboutus.php [NC]
RewriteRule ^contact/?$ contact.php [NC]

Expected behaviour: www.example.com/aboutus or www.example.com/aboutus/ calls www.example.com/aboutus.php internally. Same with "contact".
This works on my development machine, but on the hosted site, it doesn't work, throwing a 404 in both cases. Calling www.example.com/aboutus.php directly is OK, nothing wrong with the actual file. Also, .htaccess is parsed and mod_rewrite is loaded on hosted site.
Strangely, what does work is any combination of case-swapping, e.g. /Aboutus or /abOuTus. But /aboutus gives me a 404.
As an experiment, I added
Code: Select all
RewriteRule ^foobar/?$ aboutus.php [NC]

Requesting /foobar or /foobar/ gives me the aboutus.php page, which is correct but shows the inconsistency.
So the pattern seems to be: If the url that needs to be rewritten matches the case and the name (minus extension) of the corresponding file, it does not work.

Very strange indeed. I don't have access to the rewrite log, unfortunately.
Any suggestions gratefully accepted :)
zendak
 
Posts: 2
Joined: Tue May 02, 2006 12:50 pm

Postby richardk » Tue May 02, 2006 1:50 pm

It's probably a conflict with another Apache module (one that runs before mod_rewrite), perhaps mod_negotiation and MultiViews.

Or do you have a folder of the same name (/aboutus)?

What happens it you change the filenames (change case or add/remove something) so they're not the same as the file (minus the extension)? Eg. /aboutus1.php or /aboutUs.php instead of /aboutus.php. It'll probably run like the foobar test. Is that an acceptable solution?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zendak » Tue May 02, 2006 2:51 pm

richardk wrote:It's probably a conflict with another Apache module (one that runs before mod_rewrite), perhaps mod_negotiation and MultiViews.

That seems to be it. See further down.
Or do you have a folder of the same name (/aboutus)?

No.
What happens it you change the filenames (change case or add/remove something) so they're not the same as the file (minus the extension)? Eg. /aboutus1.php or /aboutUs.php instead of /aboutus.php. It'll probably run like the foobar test. Is that an acceptable solution?

OK I tried that and yes, renaming the files worked, which confirms your theory. As a quick solution I've disabled MultiViews for now in the .htaccess
Code: Select all
Options -MultiViews

That way the filenames need not be changed. Will have to investigate if that poses any disadvantages for this particular site or in general.

Thanks a lot for the hint, that was the last thing I would have thought of (if at all)!
zendak
 
Posts: 2
Joined: Tue May 02, 2006 12:50 pm


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 3 guests

cron