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

﹥>﹥吖頭↗ 提交于 2019-12-03 01:02:55

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)

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!