What’s the difference between example.com and www.example.com

502-errordomain-namedomain-name-system

I'm a developer and I'm having trouble setting up some hosting, and I hope you guys can help me out.

I've got a domain I'm setting up for a friend. URLs work fine when I use the short form, like http://example.com. That is, the pages render properly and I get HTTP/200 responses. When I try http://www.example.com, however, I get a HTTP/502 error. Pinging it gives me,

Ping request could not find host www.example.com. Please check the name and try again.


I'm stumped, because I don't know enough terminology to formulate a good keyword search. Can anyone give me some info on what I might need to do to set up some kind of alias so that the standard www. form will work? I don't know whether to talk to my registrar or my hosting company, what to ask them for, or where to look in the various control panels.

Any help at all — even just naming the different pieces — would be helpful. I don't know my TLDs from my domain aliases from my CNAMEs.

Best Answer

There's really no difference in these two names other than the fact that one has a subdomain prepended to it and the other doesn't. You can set up resource records to take advantage of an almost unlimited amount of subdomains once you own a domain name.

There are at least 30 different types of resource records. For now you can probably get by with focusing on two:

  • aname ("a" record - primary address record)
  • cname (Alias of one name to another)

www is by far the most common subdomain but there are many others. Take a look at the following examples:

  • gmail.google.com
  • my.yahoo.com

What you need to understand is that google.com and yahoo.com are domain names. Anything before that is referred to as a host name or a subdomain. As long as you take the necessary steps to set up your DNS resolution to resolve these subdomains to either their own IP address (use A Name) or as an alias (use a Cname) and you set up your webserver to understand such requests you'll be set.

In your case you should use a cname to point www.domainname.com to domainname.com. A cname is more appropriate as an answer only if you intend to point both to the same IP. That way if you need to change your IP in the future, you'll only need to adjust one record.

As for getting your webserver to understand both requests there are lots of examples for both Apache and IIS on serverfault. Do a search and you'll find everything you need. Look for virtual hosts.

Edit: Here's a cross reference about cnames. They have their place too. Use the tool that best suites your circumstances.

Related Topic