Forum Moderators: phranque
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^(.*)\.[A-Za-z]{2,4}$
RewriteRule ^(.*)$ index.php [L]
The next-to-last line is the problem. I wrote it to avoid sending requests for missing files (photos, js, etc) to my controller in index.php. (It basically says, if the request ends w/ a dot followed by 2 to 4 letters (as in a file extension), that condition is false.)
On my server(Apache 2.2.9), it works fine. On the production server (Apache1.3.41), it seems to ignore the regex.
So, if I put an <img> tag with a non-existent file, my server returns a 404 error, which is what I want. But, on the production server, I would get an error from my controller as if Apache ignored my condition, or it failed the regex for some reason.
Anyone have an idea?
RewriteEngine on
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.[a-z]{2,4}$ index.php [NC,L]
As documented by Apache, RewriteConds are only processed if the RewriteRule pattern matches, and if you must do file- and/or directory-exists checking or reverse-DNS lookups, then the RewriteConds used to do these functions should be the very last ones whenever possible, and the rule pattern should be made as specific as possible to avoid processing any RewriteConds unless necessary.
RewriteBase / is the default, and isn't needed unless preceded in this file by RewriteBase /<something-else> directive, making it necessary to reset it to default for further rule processing.
Jim
See Apache core "Options" directive and (on Apache 2.x only) AcceptPathInfo
Also it may be obvious, but should check to be sure that index.php is not defined as your 404 error document (ErrorDocument directive).
Jim
If you specify a full URL instead, then your server will generate a 302 redirect to the error document, and will not return a proper 404-Not Found response. Although the Apache documentation warns about this specifically, few Webmasters ever bother to read the documentation for the directives they try to use, so this is an extremely common error... and it can really sink a Web site!
Right:
ErrorDocument 404 /errors/my-custom-404-page.xyz Wrong:
ErrorDocument 404 http://example.com/errors/my-custom-404-page.xyz Jim