Question

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

Was it helpful?

Solution

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)

OTHER TIPS

Can what I'm asking for be done?

No, not with DNS.

You could setup something with something like a dyndns.com webhop. Basically you point www.posterous.com at the dyndns server, when a browser connects they send an HTTP 302 redirect to the url you want (posterous.com).

http://www.dyndns.com/services/webredirect/

I'm not sure if you can do this with DNS, but I'm positive that you can perform it with some javascript trickery in your blog template. I.e., a javascript snippet that is run on each page load could check the server of the current page, and rewrite the location if this matches the "www." prefix. Granted, there will be some flickering as the page loads and then reloads, and search engines will also disregard this redirect, so your content might show up under the wrong address in search results, but at least the users will see the correct, intended address.

Alternative idea: If your DNS registrar provides free-of-charge web service in addition, do the redirection there, add a rewrite rule to translate the request path to a script argument, and for each request, generate a simple page with an iframe accessing the real content. This again requires some PHP coding, but it shouldn't be too difficult.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top