favicon and multi site

I would use a rewrite to map requests for /favicon.ico to /icons/example.com.ico:

RewriteCond %{REQUEST_URI} ^/favicon\.ico
RewriteCond %{SERVER_NAME} ^(www\.)?([a-z0-9]+)
RewriteCond %{DOCUMENT_ROOT}/icons/%2.ico -f
RewriteRule . /icons/%2.ico [L]

Note the regex for line #2 depends on your set-up – is each website its own domain, or a subdomain/subdirectory of a primary domain?

I would also place a default favicon in the root, which will get pulled if no favicon exists in /icons for the current site.

Leave a Comment