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

后端 未结 7 1207
余生分开走
余生分开走 2021-02-18 21:48

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?

相关标签:
7条回答
  • 2021-02-18 21:59

    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%.

    0 讨论(0)
  • 2021-02-18 22:01

    /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.

    0 讨论(0)
  • 2021-02-18 22:01

    Looking at your logs, you will probably see such 404 errors:

    • favicon.ico: Internet Explorer, Chrome...
    • apple-touch-icon.png: iOS devices, Android, maybe some other devices
    • apple-touch-icon-precomposed.png: iOS devices, Android, maybe some other devices
    • apple-touch-icon-76x76.png: iOS, maybe some other devices
    • apple-touch-icon-120x120.png: iOS, maybe some other devices
    • apple-touch-icon-152x152.png: iOS, maybe some other devices

    If you absolutely don't want to add a favicon to your site, you can apply one the the solution described in the other answers:

    • mod_rewrite
    • Force 404
    • Empty picture

    However, favicon are so common nowadays that you probably want to add one to your site. This favicon generator creates all these files at once. Full disclosure: I am the creator of this site.

    0 讨论(0)
  • 2021-02-18 22:03

    Webbrowsers use this to display the image you see in your favorites as well as the icon of your tab. e.g. when you go to stackoverflow the cool icon you see in the tab as shown : alt text is automatically fetched by my browser (chrome) using the url : https://stackoverflow.com/favicon.ico . Its pretty standard so in case you don't want it in your log you should put some icon and rename it as favicon.ico in the httpdocs.

    0 讨论(0)
  • 2021-02-18 22:10

    Not really need it.

    However it is used on your site (the warnings).

    Check the source of your website to see if it contains:

    <link rel="shortcut icon" href="favicon.ico">
    

    In the head section of the page.

    Remove that line or add the favicon to prevent erros in your log.

    0 讨论(0)
  • 2021-02-18 22:16

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

    0 讨论(0)
提交回复
热议问题