Aug 182010


How do I point “” at “” or vice-versa?

You may have your webserver setup for either or just and you want it to work either way, whether people type in the “www” part of your domain or not. (By way of info, “www” is purely a convention, it isn’t in itself necessary to “make your domain work” over the web).

There are a couple ways to do this:

Setup a host record or A record for the root domain. Then create a CNAME record or alias which points at this host record.

In a bind style zone file you would put this:                   IN A                 IN CNAME

Take special care to make the root domain the host/A record and the “www” hostname the alias/CNAME. If you do it the other way around, more often than not, you will cause your zone to fail with errors because under most circumstances, the root of your zone cannot itself be an alias/CNAME.

Alternatively, you could simply setup a host record for each record, both pointing to the IP address:                   IN A                 IN A

The first method has a slight advantage in that you only need to change one record if the IP address of your webserver changes. If you are using an outsourced DNS host to do this, the interface usually calls the A records “hosts” and the CNAME records “aliases”. Often people get this far and then their website loads fine under one method (say, but they get unexpected results from the other, such as an error “No website configured at this address” or getting some other website entirely. This is because you still need to tell your webserver to respond to both hostnames.

When a user accesses a website in her browser, the browser sends a header setting an environment variable called HTTP_HOST, and webservers key off of this value to decide which local “webhost” or “virtualhost” to load (this is how web hosting companies can host thousands of websites on a single IP address.) In our example, we’re using the apache webserver, and you need to specify in your “VirtualHost” directive that the website needs t respond to requests from both and, you do this with a “ServerAlias” statement:



ServerAlias     *

# other stuff


You can add multiple entries per ServerAlias line, in our example above we have added a “wildcard” entry for, if you setup a wildcard DNS entry in the zonefile, this webserver would load properly for You could also enter multiple ServerAlias lines, if you wanted your website to respond on another domain name as well.

Share This!
 Posted by at 1:30 am

Sorry, the comment form is closed at this time.