Welcome to WebmasterWorld Guest from 54.198.118.102

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to exclude favicon.ico from custom 404 page

I am sure this is only one line in HTACCESS, pls help

     
10:54 pm on Jul 8, 2008 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Apr 30, 2008
posts: 2630
votes: 191


I am currently redirecting all not found URLs to a custom 404 page using the following in my .htaccess:

# 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?

11:01 pm on July 8, 2008 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9074
votes: 6


I don't have a direct answer, but you can simply create or upload a zero-byte file called "favicon.ico" into your site's root directory - and then the request won't produce a 404 at all.
11:04 pm on July 8, 2008 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Apr 30, 2008
posts:2630
votes: 191


Hi, thanks for the answer, but as far as I could figure out, the favico.ico may have some special handling by browsers so I am not sure if this would cause any knock-on effect somewhere else.

So I would prefer to exclude favico.ico file from custom 404 page processing instead.

11:21 pm on July 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Aug 29, 2006
posts:1312
votes: 0


I would advise you to do it like 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.

...

3:32 pm on July 9, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


In order to avoid massive problems with search engines, you MUST NOT rewrite 404 errors. Doing so will return a 200-OK status to all requests, and therefore confuse search engine robots, open your site to malicious linking exploits, create 'infinite' duplicate content, and a host of other ills.

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

10:00 pm on July 9, 2008 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Apr 30, 2008
posts: 2630
votes: 191


Many thanks to everyone who replied. I have changed .htaccess to use ErrorDocument instead of RewriteRule and have also added favicon as suggested and it all works.

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.

10:47 pm on July 9, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Aug 29, 2006
posts:1312
votes: 0


I would simply remove the ErrorDocument reference from the WordPress .htaccess - the one in your site root will handle all 404s - and perhaps put two links in the error404.html (one to the home page and one to the blog folder, both with absolute paths).

...

10:55 pm on July 9, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members