Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DNS Gurus: How to forward www.domain.com to domain.com using DNS only? [closed]

I am running a blog at posterous.com, and they can host my domain name if I create an A record to their IP in my domain registrar's custom DNS tool.

The problem is that I want my domain to ALWAYS read domain.com, so I want to have my DNS remap any requests to www.domain.com to domain.com, and I can't use .htaccess or PHP or other server methods, since it's just a blog interface.

So far, I've tried:

@ A target.ip.address
www CNAME domain.com

Which redirects www.domain.com to the right site, but the www. is still on the domain. I heard you could do:

@ A target.ip.address
www A internal.redirector.ip.address

but I don't know my registrar's internal IP address that might handle this redirection (or even if such a thing actually exists).

Can what I'm asking for be done?

Thanks, you guys rock.

-Josh

like image 311
iopener Avatar asked Feb 27 '09 07:02

iopener


People also ask

How do I direct a domain to www?

Redirecting Your Domain to www URL. Keep the Type as the default, Permanent(301). Select your domain name from the drop down menu on the next line. In the redirects to text box, type in the full URL of your domain, including www (e.g. http://www.yourdomain.com). Select the radio button next to Do Not Redirect www.


1 Answers

No, you can't do this with DNS - the result of the DNS query doesn't change what happens in the HTTP layer so the originally entered domain name will always be the one that's sent to the web server in the Host: header.

Web browsers only look up A records in the DNS, and it's the user's ISP's recursive name server which detects that the name actually only has a CNAME record, which it then looks up, and returns the IP address corresponding to that name in the CNAME record.

The usual C gethostbyname() API doesn't return any of that CNAME information to the application, all it ever gets is the final resulting IP address.

To achieve what you want you'd need to arrange for www.example.com to have separate hosting from your blog, and then have that site do an HTTP redirect to example.com (i.e. without the www prefix)

like image 97
Alnitak Avatar answered Oct 20 '22 09:10

Alnitak