Fork me on GitHub

article

WordPress users: USE A FAVICON!

September 18, 2009 | Web Design & Development

If you’re using a favicon on your site, then you’re fine. If you’re not:

Just recently I noticed that WordPress will do something evil: if you don’t have a favicon.ico on your server WordPress will do a 404 return on the favicon.ico request that’s made by pretty much every modern browser. To say it again, slightly differently: if you’re not supplying a favicon.ico in your webroot, or defining a valid location specifically in your page head, WordPress is picking up the call for the non-existent file and spooling up just to show a 404 page.

This means that you’re spinning up WordPress twice for every page load just by not having a file in the server root.

BAD! BAD! BAD!

There are 2 ways to fix this.

  1. Use a favicon. Get more details about favicons at favicon.com. You can also create one quickly if you just want to get at it.
  2. Modify WordPress’ .htaccess rules to exclude the favicon.ico file from being an option for WordPress to handle. I’ll show you how to do that next.

The fix, if you don’t want to add a favicon file to your site, is pretty straight forward, but requires modifying a file on in the webroot. You’ll need to have file system level access to your server and permissions to write to this file. If the WordPress install was done automatically by the host or through a control panel you may not have permissions to edit this file and may find it easier to just add a favicon to your web root.

This is the line you want to add to your .htaccess file:

  1.  RewriteCond %{REQUEST_FILENAME} !favicon.ico

Insert it in your .htaccess file so that the effected section looks like this:

  1.  RewriteCond %{REQUEST_FILENAME} !-f
  2.  RewriteCond %{REQUEST_FILENAME} !-d
  3.  RewriteCond %{REQUEST_FILENAME} !favicon.ico
  4.  RewriteRule . /index.php [L]

On WordPress MU you’ll look like:

  1.  RewriteCond %{REQUEST_FILENAME} -f [OR]
  2.  RewriteCond %{REQUEST_FILENAME} -d
  3.  RewriteRule . - [L]
  4.  RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
  5.  RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
  6.  RewriteCond %{REQUEST_FILENAME} !favicon.ico
  7.  RewriteRule . index.php [L]

This will cause the 404 to be handled by Apache which will be much less resource intensive than letting WordPress handle it. The best solution, though, is to provide a favicon.ico in your server root, then everybody, including the server, is happy.

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Mentions

  1. WordPress users: USE A FAVICON! – The Gippy Pages Hello CMS - the best cms website

    […] from:  WordPress users: USE A FAVICON! – The Gippy Pages By admin | category: Object, WordPress | tags: been-exploited, evening, every-modern, […]

    September 18, 2009 | 9:35 pm

  2. Around the web | alexking.org

    […] WordPress users: USE A FAVICON! – The Gippy Pages – we’ll submit a core patch for this too. […]

    September 20, 2009 | 2:02 pm

  3. Brian Dusablon

    This Week in Browsing…

    Hacked Again – good insight into WordPress backups and security
    Dan Cederholm (SimpleBits) Goes WP – Wow. Another big player on WordPress. Love it!
    20 Social Media Comics (via Jeff)
    Social Media is the Means to Achieve Workplace Collaborati…

    October 30, 2009 | 3:20 pm

Comments are closed