8

As the question implies, on occasion Drupal's log is showing that the favicon is not found. Indeed, it does not show in the browser tab or address bar. At other times, even within the same surfing session, it does show up.

Why does it do this and how can I prevent it so that the favicon will always show?

I am using version Drupal 7.22. with a custom subtheme and an admin theme (Stark).

My favicon is set in the subtheme theme configuration at sites/default/files/images/favicon.ico and that is located there as I have checked via FTP.

The log shows the browser is looking in example.com/favicon.ico.

The custom subtheme I use has <link rel="shortcut icon" href="http://example.com/sites/default/files/images/favicon.ico"; type="image/vnd.microsoft.icon" /> in the source code and the admin theme (Stark) uses <link type="image/vnd.microsoft.icon" href="http://example.com/misc/favicon.ico"; rel="shortcut icon"> and this file also exists in that location (not actually using example.com, of course).

Drupal is using clean URLs.

The web server is Apache on Debian Linux.

Thank you.

  • Might help if you would provide referer for these errors, should be in log. – Mołot Jul 5 '13 at 14:22
  • @Molot The referrer field is either blank or another page in the site in all cases I have checked in the log. – authentictech Jul 6 '13 at 19:01
  • Can you edit in the log message to show the path, what webserver you are using, as well as whether mod_rewrite works (ie, clean URLs)? – mpdonadio Jul 6 '13 at 22:26
4

Some browsers search for favicon under http://example.com/favicon.ico without checking. But they are minority now.

Most respect:

<link rel="icon" href="http://example.com/img/icon.png">

as described by W3C.

If your site tries to use <link> approach but fails on some pages, like admin pages rendered using different template, and you do not have favicon.ico in default location, you will get exactly described effects.

If browser is looking for http://example.com/favicon.ico when you have proper <link rel="shortcut icon"> it is a browser problem, not yours. It means browser (or at least that part of it's code) is outdated, unless it looked under correct URI first and got another error, but then you would see two errors in log, one for right place, second for outdated one. In Mozilla's queue there is a number of reports about improper favicon detection by FireFox - in example this one. It shows how even modern browsers can sometimes fall back to old methods.

  • Yes the log shows the browser is looking in example.com/favicon.ico. The custom subtheme I use for the site does give <link rel="shortcut icon" href="example.com/sites/default/files/images/favicon.ico" type="image/vnd.microsoft.icon" /> in the source code (not actually example.com) which is the correct location. If I turn off the overlay, the admin theme is using <link type="image/vnd.microsoft.icon" href="example.com/misc/favicon.ico" rel="shortcut icon"> and this file also exists in that location. – authentictech Jul 6 '13 at 19:19
  • Everything seems correct as it should be. So is this a browser problem or website problem? Where would I go to fix it? Thanks. – authentictech Jul 6 '13 at 19:21
  • @authentictech if browser is looking for example.com/favicon.ico when you have proper <link rel="shortcut icon"> it is a browser problem, not yours. It means browser is outdated, unless it looked under correct place first and got another error, but then you would see it in logs just before this one. I'll update my question. – Mołot Jul 6 '13 at 21:22
  • 1
    @MPD It might not be served by Apache; Pantheon's nginx config omits that rule for example (if I remember rightly) – Clive Jul 6 '13 at 22:29
  • 2
    @authentictech Firefox has numerous open bug reports about improper favicon handling. Like this one for example. Parts of it's code are old, sad but true. If you want to handle that, you can add rewrite to your .htaccess, but it will be hacking around a browser bug, not fixing site bug. – Mołot Jul 8 '13 at 9:53
2

Quick and easy fix for this pain, is to use the Redirect module and make a redirect for it.

Once the module is enabled, go to admin/config/search/redirect/add and use favicon.ico under from and to should be the actual location of your theme's favicon.ico.

  • This file is automatically handled by .htaccess so the request never makes it to Drupal for the Redirect module to handle it. – Vincent Apr 9 '17 at 4:41
  • 1
    Yes it does make it to Drupal. Otherwise how would it be logged in the Drupal log? I have used this approach successfully in production. – cdmo Apr 9 '17 at 10:40
  • 1
    You are right, i just tested this. Edited your original answer so that I can switch my downvote to an upvote. – Vincent Apr 10 '17 at 11:59
0

If you're using Apache, the best way I found to fix it is to put:

<Location /favicon.ico>
  ErrorDocument 404 "No favicon"
</Location>

This code should work in your vhost file or should also work in the .htaccess file, see http://httpd.apache.org/docs/2.4/sections.html for more details

-1

You can try https://www.drupal.org/project/favicon It to make requests to http://example.com/favicon.ico forward to the actual site's true favicon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.