Posted by & filed under Developer Blog.

For years (literally over 2 years) my company has been dealing with an issue where after loging into the intranet using any Mozilla browser (including Netscape and Firefox), it would direct you to the favicon.ico rather than the home page. We are using a protected Java Servlet on a JBoss server to serve up the intranet pages. If the favicon was not present, it would give a 404 error or would say it had not been defined. I’ve spent hours trying to solve the problem, mostly by trial and error, renaming files, adding link data to the head of the index page and everything else I could think of.

Today, however, I finally found the solution!

The problem does not lie in the index page, but rather in the login page. Mozilla browsers automatically look for the favicon.ico in the root directory if there is no link tag in the head of your document. When you attempt to access any protected page without logging in you are directed to the login page. Mozilla is looking for the favicon on the login page and the favicon is protected so it theoretically redirects you again to the login page so that you can access the favicon for the login page. Hence when you log in, you do access the favicon and not the page you were looking for in the first place.

To combat this problem, you need to set up an unprotected directory where the favicon resides and place the following code on your login page:

<link rel="icon" href="unprotected/favicon.ico" type="image/ico">
<link rel="shortcut icon" href="/unprotected/favicon.ico">

This tells the browser to look for the favicon in a location other than the default root directory. Problem solved!