How to A-record DNS redirections work?
February 19, 2011 8:21 AM   Subscribe

Some DNS registrars offer a service where they redirect anybody landing at http://yourdomain.com to http://www.yourdomain.com. What do they do to the DNS record to make this happen, particularly if the www is a CNAME record (that is, not an IP address)?
posted by deeper red to Computers & Internet (12 answers total) 1 user marked this as a favorite
 
Can you give an example of a service that does this through DNS?
I don't think it's the DNS registrars doing this, since the DNS protocol has no idea what port you are trying to connect to or what protocol you are trying to use.

More likely, it's the web hosting service doing this, which doesn't even require a redirect; it's just another Server Alias (or Virtual Host).
posted by jozxyqk at 8:27 AM on February 19, 2011


My DNS settings through Nearly Free Speech (my web host) do this. Article of interest.
posted by jmd82 at 8:34 AM on February 19, 2011


I believe they just give the root an A record which points to their web server, which is configured to do the redirect.
posted by makeitso at 8:38 AM on February 19, 2011


If you want the person's browser to actually show the url www.yourdomain.com when they put in just yourdomain.com, that is not possible just with DNS. A redirect is needed on the web server answering for yourdomain.com. So if a DNS provider is to have this server, they actually have a web server answering for yourdomain.com and sending an HTTP 301 redirect to www.yourdomain.com.

On preview, what makeitso said.
posted by zsazsa at 8:38 AM on February 19, 2011


so for my domains I have an A record that points to the non www domain. I can then have a CNAME record for www which points to mydomain.com. This takes care of the DNS records.

I don't "redirect" www.mydomain.com to mydomain.com I use a ServerAlias
posted by bitdamaged at 9:06 AM on February 19, 2011


Bitdamaged, it's the other way around that I'm interested in.
posted by deeper red at 9:35 AM on February 19, 2011


What do you mean the other way around?
posted by bitdamaged at 9:49 AM on February 19, 2011


A records create a mapping between an IP address and a name. That's all they do. There is nothing happening in DNS that's redirecting web browsers to the "www." version of a URL.

Here's how that happens (leaving out a few steps about authoritative nameservers and root nameservers and such):

1: You type "http://yourdomain.com" into the browser's address bar and hit enter.
2: Your machine asks a nameserver to resolve "yourdomain.com."
3: The nameserver determines from your domain registrar what the authoritative nameserver for yourdomain.com is -- this won't necessarily be a nameserver controlled by your domain registrar, though it often is.
4: The nameserver you contacted contacts the authoritative nameserver for yourdomain.com and asks to resolve "yourdomain.com". The authoritative nameserver, which has either a CNAME or an A record for "yourdomain.com" returns the result, which is passed along to your machine.
6: Your browser opens a connection to the HTTP server running at the IP returned by the DNS query and makes a request for http://yourdomain.com/
7: The HTTP server redirects the browser to http://www.yourdomain.com/
8: Steps 2 through 6 are repeated.
9: Your browser opens up a connection to the HTTP server running at the IP returned for "www.yourdomain.com" and makes a request. The URL bar now says "http://www.yourdomain.com/".

The important thing here is that the redirection happens on the HTTP server, not the DNS server. What everyone else has been telling you is true. If your domain registrar is also your DNS and HTTP host, then they can sell you this as a package and hide the details from you. I have at least one domain that I have to do this manually for -- I registered it through Dotster, DNS is hosted by Dreamhost, and the HTTP server is on Linode. Neither Dotster nor Dreamhost can do anything to make http://mydomain.com/ redirect to http://www.mydomain.com/. I have to do that myself, on the HTTP server I run at Linode.
posted by hades at 9:55 AM on February 19, 2011 [2 favorites]


Forgot to mention: the HTTP server answering to "yourdomain.com" and the HTTP server answering to "www.yourdomain.com" may or may not be the same server. It doesn't really make a difference. The yourdomain.com HTTP server could be something your DNS host provides for the express purpose of redirecting their customers' top-level domains to "www", or it could just be an extra line in the configuration of the HTTP server your web host for www.yourdomain.com runs.

The type of record is a red herring. Both yourdomain.com and www.yourdomain.com could have A records or CNAME records and the behavior would be the same. The redirection doesn't take place in DNS.
posted by hades at 10:03 AM on February 19, 2011


deeper red: Are the registrars who are doing this also hosting the website in question?
posted by rhizome at 11:38 AM on February 19, 2011 [1 favorite]


Echoing what makeitso and others have said, I assume the registrar is running the webserver pointed to by mydomain.com, but the only thing that webserver does is issue a redirect to www.mydomain.com, which can be hosted anywhere. (I tried reading jmd82's link but it seems to be for logged-in users only.)
posted by hattifattener at 2:58 PM on February 19, 2011 [1 favorite]


If you want the url in the browser to change (that is, you typed 'A', resulting page reads 'B') then you must have something more than DNS in the mix, in particular you need a HTTP server that responds with a 30x code and 'Location' header. If the DNS provider is not hosting the site, then they must have the name resolve to a different IP address of a server under their control that sends the redirect. If they are hosting the site they can have both domains resolve to the same IP address and then do the redirect.
posted by Rhomboid at 4:52 PM on February 19, 2011


« Older Boston North End Apt Search   |   I want to buy a really boring car. Newer »
This thread is closed to new comments.