Jul 1, 2009

Shortcut icon in a TYPO3 multidomain installation

Creating a shortcut icon in the TYPO3 multidomain installation can be a tricky option. Modern browsers (like FireFox, for example), support a link tag that allows to place shortcut icons to pages. There can be transparent gif or png files. The syntax is simple:
<link rel="icon" type="image/gif" href="/fileadmin/icons/www.gif" />
In TYPO3 you can add it through the normal page.headerData or page.shortcutIcon TypoScript.
Luck ends here. The most popular browser, Microsoft Internet Explorer does not recognize this tag, requires the file to be named favicon.ico, be placed in the root of the web site and supports only Windows proprietary icon file format (.ico). So you can hardly have different icons for the Internet Explorer without tricks.

Creating icons

Creating Windows icons is easy if you have ImageMagick installed. Just execute:
convert www.gif www.ico
You can use any other tool but ImageMagick is probably the simplest, it converts without quality loss and preserves transparency.

Tricking Internet Explorer to show different icons

Next we have to trick Internet Explorer to receive different files for different sites that are physically located in the same file system space. As usual for such cases, mod_rewrite is our great friend. Assuming we have two icons for two domains, we use these rules in the virtual host configuration:
<LocationMatch "^/favicon.ico$">
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www
RewriteRule .* /fileadmin/icons/www.ico [L]
RewriteCond %{HTTP_HOST} ^subdomain
RewriteRule .* /fileadmin/icons/subdomain.ico [L]
</LocationMatch>
Note that we do not use 301 or 302 redirects. They do not work well with Internet Explorer. We have to do internal redirects.
This makes all requests to favicon.ico forwarded to proper real files.

3 comments:

  1. Nice. Thanks for sharing.



    Bloody IE :-(

    ReplyDelete
  2. In IE7 you can place your favicon wherever you want. I made a multidomain installation with more than 20 domains. Perhaps IE6 makes problems...

    ReplyDelete
  3. Sven, does not work for me in MSIE7... How do you do it?

    ReplyDelete