Website URLs and Domains

703 views

Hello,

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

Specifically, if you own a domain such as: yourwebsite.com

If you have the domain records setup so that the CNAME www.yourwebsite.com -> yourwebsite.com

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

2 Answers

Anonymous 0 Comments

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.

Anonymous 0 Comments

The DNS records tell a browser where the server is. So if you ask your browser to go to https://www.example.com/, the browser looks up www.example.com. If it finds a CNAME record pointing to example.com, it will know it should look at the record for example.com 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 `example.com`, 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 `example.com/`, 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 `www.example.com/` instead.

Even though it’s the same server, it’s giving different answers whether you’re looking up the “correct” address at `www.example.com/` or the “incorrect” one at `example.com/`. 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.