Question

Favicon only showing when I type www.websitename.com not websitename.com

Why does this happen and how can I make favicons show up on websitename.com.

Was it helpful?

Solution

The default favicon is simply downloaded from the current Host of the HTTP request, plus `/favicon.ico'--and this Host is different in your two examples. There is nothing that says the host preceded by a "www." has anything in common with the host without the preceding "www."

There are three cases that may apply to you.

  1. The favicon might be served from a literal file named favicon.ico and located in your document root. In this case, you need to check that your server's vhost (virtual host) configuration is set up to resolve both hosts "www.websitename.com" and "websitename.com" equivalently to the exact same set of files. (Although in general, this is not a good idea. See N.B. below.)

  2. The favicon might be served from a file (named almost anything and located either inside or outside of your document root) which is set as your favicon by a server configuration. So check the server configuration and make sure that the rule determining the location of the favicon is applied to both hosts without and without a leading "www." Once again, these are in general completely different hosts, and a server does not normally assume there is anything in common between them.

  3. You might be specifying the favicon individually in each file with a link HTML tag. If so, then make sure that the same HTML files are being loaded at each Host, as in answer 1, and follow this format for you link tag. (Your current rel attribute does not look like it will trigger most browsers into displaying the icon.)

    Necessary to add link tag for favicon.ico?

N.B. There is a good reason why those hosts are not considered equivalent. Consider the case that half of your visitors randomly link to an article at your site with the "www." and half of them don't. And imagine this happens for every other website as well. Then slowly the internet, search engines, bookmarks become uselessly filled up with multiple links for every resource. Everything gets crawled at least twice as often for each distinct link, and resources are continually wasted forever and ever.

It is a good idea, therefore, to make your main body of content accessible only under one Host (whichever you prefer), and redirect the other host to the home page of the correct one. In the long run this will help your own server and will also help both you and the internet. By allowing only canonical links to work in the short run, one ensures that only canonical links will exist in the long run.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top