Posts Tagged ‘custom 404 htaccess apache’

Custom 404 not Correct

Tuesday, January 29th, 2008

I just had a harrowing experience: some of the custom 404 pages I set up were returning the wrong HTTP status code. A nonexistent page should return a 404 status code and be redirected to a custom 404 page (the structure is another story in itself). But…the nonexistent pages were returning a 200 status code, which means everything is ok…and it’s not.

This is the way I was given by my host (actually one of the ways) to redirect a 404 to a custom 404 page:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /custom404.php

This does redirect a nonexistent web page to the custom404.php page but it causes the bad page to return a 200 instead of a 404.

ErrorDocument 404 /custom404.php

This is what I replaced the last three lines with. Now the errant pages return a 404 rather than a 200.

BTW, I use Fiddler to check the return codes.

Doug