Possible Duplicate:
to www or not to www

Consider a website at www.example.com

When the URL is entered manually into Firefox's address bar as example.com , the browser automatically redirects to www.example.com.

Using Internet Explorer, the browser redirects to a default search engine with the search term for example.com.

Sites like codinghorror.com or example.net all are automatically changed to redirect to their www address.

Is there a setting on the web server to change this behaviour?

Any other issues coming into play here?

  • 3
    One should note that Firefox is rewriting your "example.com" into "www.example.com" because "example.com" does not resolve. IE, instead, doesn't, and points you to the search engine. To fix, "example.com" must resolve (as pointed out below).
    – Mei
    Jul 9, 2009 at 16:03

5 Answers 5


Generally, you set up your webserver so that one domain is canonical, and any aliases you want are redirected to it. If specify which webserver, someone will be along shortly to tell you how :)

With Apache, you might do something like this:

<VirtualHost *>
    #our canonical name
    ServerName www.example.com

    #other domains we want to respond to
    ServerAlias example.com

    RewriteEngine on

    #if host is specified and not our canonical one, redirect
    RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteRule ^/(.*)         http://www.example.com/$1 [L,R=permanent]



Note that you must still define A or CNAME records for all the aliased domains.

  • 1
    You also need to ensure both addresses are setup as A records or CNAMEs in DNS.
    – Brent
    Jul 9, 2009 at 15:59

I'd recommend setting up one of the two names to be the canonical and unique way to access your web site and the other to redirect to it. Don't use CNAME, or JavaScript redirection. Use HTTP redirection.

Personally I redirect from www.example.com to example.com because I'm against www. The reason is quite simple: the fact that you are using a web browser and http already says that you are trying to access the web site at that location, no need to add more redundant information. Also, hr.example.com may be HR's web site, does that mean then that you have a www department at your company? and if not, then it should be www.hr.example.com, which looks rather bad.

  • 1
    exactly my thoughts. see no-www.org
    – Javier
    Jul 9, 2009 at 16:24
  • You're still going to need to be able to send one from the other. Kind of hard to do that if you can't get to the one.
    – Kevin M
    Jul 9, 2009 at 18:02
  • 1
    This is all fine and good, but cookies set at the TLD are leaked to the subdomains. If it wasn't for this cookie behavior I would totally be on board with the NO WWW. Jan 24, 2011 at 23:48
  • @Javier google.com seems to disagree with you there
    – Pacerier
    Sep 14, 2011 at 6:20
  • @Clint do you mean to say that if the TLD domain starts with www, the cookies set at the TLD wouldn't be leaked to the subdomains ?
    – Pacerier
    Sep 14, 2011 at 6:21

Look at the url above. stackoverflow.com doesn't go to www.stackoverflow.com. They are two separate dns entries. Take a look at your DNS host configuration and try to add an A record for xyz.com and that should fix the problem.


As already mentioned, you're going to have two separate DNS records. If this is desirable (e.g. you don't just want www.example.com), then you want to have one name to be the canonical name. This is important for things like cookies to work as you intend for your end users.

I don't know what web server you're using, but if it's Apache then you'll use URL rewriting as described at the following page:


Search the document for "canonical hostnames".


See the Stack Overflow question on the issue: Should I default my website to www.foo or not?

Not the answer you're looking for? Browse other questions tagged or ask your own question.