5

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?

Broken Link
  • 161
  • 1
  • 5
  • 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 09 '09 at 16:03

5 Answers5

4

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]

    ...

</VirtualHost>

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

Paul Dixon
  • 1,436
  • 3
  • 21
  • 35
3

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.

Pablo
  • 7,249
  • 25
  • 68
  • 83
  • 1
    exactly my thoughts. see http://no-www.org/ – Javier Jul 09 '09 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 09 '09 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. – Clint Pachl Jan 24 '11 at 23:48
  • @Javier http://www.google.com seems to disagree with you there – Pacerier Sep 14 '11 at 06: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 '11 at 06:21
  • @ClintPachl is this what you are saying: http://stackoverflow.com/questions/6638087/when-we-do-a-refresh-on-a-page-that-was-previously-get-request-are-the-headers-s/7536123#7536123 . Correct me if i'm wrong. – Pacerier Sep 24 '11 at 23:36
2

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.

Spencer Ruport
  • 477
  • 3
  • 17
2

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:

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Search the document for "canonical hostnames".

Boden
  • 4,948
  • 12
  • 48
  • 70
1

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

Sam Hasler
  • 301
  • 3
  • 13