Website URLs and Domains



Can someone please explain how website URLs and domain names interact?

Specifically, if you own a domain such as:

If you have the domain records setup so that the CNAME ->

How does the www version become the default web address and how is 301 redirects applied?

If www is pointed to naked domain, why does the website default to www version – shouldn’t it be the other way around? Or is this web server configuration based?

In: Technology

The DNS records tell a browser where the server is. So if you ask your browser to go to, the browser looks up If it finds a CNAME record pointing to, it will know it should look at the record for instead. And when it does that, it will find the IP address of the web server.

To that IP address, it will send a GET request, saying “get me the file at `/`”, that is, the top-level page or homepage. The server will look for that file and respond with it. If it’s an HTML file like most websites are, it will contain text and can contains link to other files that it tells the browser it should look up as well, like stylesheets and images.

Note that in this example, it’s not necessary to use the `www` hostname. You’ll get exactly the same result if you skip that step and go straight to ``, since the CNAME record is just pointing to this record. What if you want to make it so that people *have* to use `www`? You have to set that up at the server level. People will still be able to find the server by going to ``, but you’ve set it up so that instead of responding with the page they’re looking for, the server tells them go find it at `` instead.

Even though it’s the same server, it’s giving different answers whether you’re looking up the “correct” address at `` or the “incorrect” one at ``. It can do this is because those URLs are different and so they can have totally different contents and actually, there’s no reason those addresses need to point to the same server at all.

These are setting that can be configured on the server settings or defined site’s cpanel. You can set up what is the canonical version of the site, and redirect the non-canonical to it. Hosting setups may default to www. but you could change to drop that if you choose to do so fairly simply.