Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to have a favicon on my site? How do I get rid of the errors I see in my apache log?

Tags:

favicon

I keep seeing favicon warnings in my apache log. How do I get rid of those? Do I have to have a favicon for my site?

like image 495
milesmeow Avatar asked Nov 24 '10 17:11

milesmeow


4 Answers

/favicon.ico is one of the artifacts of the Browser Dark Ages (cca 2000). While there is no way to prevent the browser requests, creating a 0-byte file named favicon.ico ends the flow of 404 errors (as the file exists), but no favicon will be shown by the browsers for your site.

like image 117
Piskvor left the building Avatar answered Oct 12 '22 23:10

Piskvor left the building


Johan Petersson provides a good answer to preventing file not found errors without using a favicon at http://www.trilithium.com/johan/2005/02/no-favicon/

Placing the following code in the Virtual Host section of httpd.conf (or wherever you define your site environment), should stop the errors appearing in the Apache error log:

# Don't bother looking for favicon.ico
Redirect 404 /favicon.ico

# Don't bother sending the custom error page for favicon.ico
<Location /favicon.ico>
    ErrorDocument 404 "No favicon
</Location>

Alternatively, you can create a blank file and name it favicon.ico, placing it in the root directory of the site.

like image 22
Maltronic Avatar answered Oct 13 '22 01:10

Maltronic


You don't need to, no, but some browsers will request /favicon.ico automatically, so the errors are pretty much unavoidable.

like image 45
Wyatt Anderson Avatar answered Oct 13 '22 00:10

Wyatt Anderson


You don't really need it, but as others have said, some browsers will ask for it even if it's not specified in <link rel="shortcut icon" />.

I'm not an expert, but I played with mod_rewrite a bit, and here's what you can do:

# turn on the mod_rewrite module
RewriteEngine On
# if requested file is not an existing file
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
# and it's name is favicon.ico, send an empty 410 GONE response to the browser
RewriteRule .*favicon\.ico$ - [G] 

I only tried this on my localhost: first request resulted in 410, but for all following ones, browser does not ask for that file, because it remembers it's gone.

I'm not sure this is how you're supposed to use 410 GONE status, nor that it will work 100%.

like image 44
Martin Tóth Avatar answered Oct 12 '22 23:10

Martin Tóth