DNS 大师:如何仅使用 DNS 将 www.domain.com 转发到 domain.com?

发布于 2024-07-14 10:22:45 字数 1459 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

っ〆星空下的拥抱 2024-07-21 10:22:46

不,您不能使用 DNS 执行此操作 - DNS 查询的结果不会改变 HTTP 层中发生的情况,因此最初输入的域名将始终是发送到 Host 中的 Web 服务器的域名: 标头。

Web 浏览器仅在 DNS 中查找 A 记录,用户 ISP 的递归名称服务器检测到该名称实际上只有 CNAME 记录,然后进行查找,并返回 CNAME 记录中该名称对应的 IP 地址。

通常的 C gethostbyname() API 不会向应用程序返回任何 CNAME 信息,它获得的只是最终生成的 IP 地址。

要实现您想要的效果,您需要安排 www.example.com 与您的博客分开托管,然后让该网站执行 HTTP 重定向到 example.com (即没有 www 前缀)

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)

尹雨沫 2024-07-21 10:22:46

我的要求可以实现吗?

不,不能使用 DNS。

您可以使用 dyndns.com webhop 之类的东西进行设置。 基本上,您将 www.posterous.com 指向 dyndns 服务器,当浏览器连接时,它们会发送 HTTP 302 重定向到您想要的 url (posterous.com)。

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

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/

铜锣湾横着走 2024-07-21 10:22:46

我不确定您是否可以使用 DNS 来执行此操作,但我确信您可以在博客模板中使用一些 javascript 技巧来执行此操作。 即,在每个页面加载时运行的 JavaScript 片段可以检查当前页面的服务器,并在与“www”匹配时重写该位置。 字首。 当然,当页面加载然后重新加载时,会有一些闪烁,搜索引擎也会忽略此重定向,因此您的内容可能会显示在搜索结果中的错误地址下,但至少用户会看到正确的预期地址。

替代想法:如果您的 DNS 注册商还提供免费 Web 服务,请在那里进行重定向,添加重写规则以将请求路径转换为脚本参数,并为每个请求生成一个带有 iframe 访问真实内容的简单页面。 这同样需要一些 PHP 编码,但应该不会太困难。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文