I got a free few minutes to work on my own site here. Since I migrated the site from all static pages to Django served, I still haven’t put back the favicon icon back onto the site. The sites runs under a virtual host in apache2 at WebFaction. This is what you need to put in your httpd.conf file:
alias /favicon.ico /home/your-home/your-app-etc/static/image/favicon.ico <LocationMatch "\.(jpg|css|gif|pdf|ico)$"> SetHandler None </LocationMatch> The alias line tells apache to go look for the favicon.ico file at a static location of your choice. The LocationMatch directives tell apache to not run those files thru the Django engine.


{ 6 comments… read them below or add one }
Hey there. I tried to do this following your instructions, but it’s not working for me. I put the appropriate lines in httpd.conf and restarted apache.
Do I have to do something else besides update httpd.conf? You can email me back if you are inclined at andrewljohnson [at] gmail.com
I’m using FastCGI for all my django sites and there’s an even simpler solution: Adding the following does the trick:
RewriteRule ^/favicon.ico$ /media/favicon.png [QSA,L,PT]
hey. even easier:
if you have django.redirects installed, just write a new redirect!
Is it not easier to add the favicon via a tag in the html?
I’m currently doing this in my websites, and since no-one mentions it, I’m afraid its a bad use?
The idea here is to by pass Django and just make the apache web server serves up the fav icon. Otherwise the other’s suggestions work also, but more work for Django.
Andre — the favicon tag is still needed in the HTML. This is just to deal with what happens when the browser ask for the fav icon file.
Another option, one that doesn’t require knowing the full path to this particular instance of django is to use another location directive.
So I have first, a location directive for “/” that sets the handler to django
Then one for “/favicon.ico” that sets the handler to none, and finally one for “/media” which also sets the handler to none
This follows the same style as the “serving media files” section of http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1