Forum Moderators: phranque
# RETURN CUSTOM PAGE NOT FOUND INSTEAD OF 404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? [mysite.com...] [L]
What I believe the above is saying is: "If requested filename is not file and is not directory, then show error404.html"
I would like to exclude favico.ico from the above processing, i.e. I still want to return the ordinary 404 status if favico.ico is requested (i.e. not to return custom 404 page when there is request for favico.ico), however, I still want to return custom 404 page for everything else that is not found.
Can anyone help with what do I have to put in HTACCESS to achieve this?
ErrorDocument 404 /error404.html
This is the built-in Apache method and does not require the Rewrite Engine.
Note also that you must use a relative path as shown for it to send the correct 404 status code and that links to any external files (CSS, images etc) in the error document itself should be absolute.
As encyclo said, if you don't have a file named "favicon.ico" just add one - problem solved.
...
Use the ErrorDocument method as Samizdata advises.
And by all means create a Favicon. Having a Favicon has now progressed from "nice new trick" status to "required on any decent site" status. If you can't make up your mind what you want it to look like, then put up a transparent one. This will at least get rid of the 404 errors while you make up your mind.
Similarly, you should support any and all such commonly-requested files -- If for no other reason than to make your log files and stats accurate. robots.txt and favicon.ico should no longer be considered "optional."
Jim
I have one more question though to do with Wordpress 404 page. I am using permalinks and wordpress redirects all "not found" URLs to index.php who then tries to "decode" permalink and if valid, constructs page dynamicaly, and if not valid, then issues 404 error.
Wordpress has its own 404 page and when 404 is issued, the actual response sent back to the client is not 404, it is in fact 302 response redirected to custom wordpress 404 page which, when displayed, comes up in log with response 200. Hence, in wordpress the 404 is actually never returned. Would this cause the same problem with search engines as described above?
Forgot to say that wordpress blog is in a folder under the main site, e.g. www.mysite.com has own htaccess which I changed to add ErrorDocument, and there is also www.mysite.com/blog which has htaccess that deals with wordpress permalinks.
Wordpress has its own 404 page and when 404 is issued, the actual response sent back to the client is not 404, it is in fact 302 response redirected to custom wordpress 404 page which, when displayed, comes up in log with response 200. Hence, in wordpress the 404 is actually never returned. Would this cause the same problem with search engines as described above?
Yes, 302 responses are deadly.
Jim