使用 CNAME 重定向不起作用

Den*_*nis 2 domain-name-system

我尝试使用 CNAME DNS 条目进行重定向。

www.example.com -> othersite.com
Run Code Online (Sandbox Code Playgroud)

当我输入www.example.com时 ,我收到“找不到文件”错误。有一个文件:othersite.com/index.html 消息指的是哪个文件?

Håk*_*ist 6

DNS 中的记录CNAME不是 HTTP 重定向,它是 DNS 本身内的别名。

即,在您的示例中,它使得查询的解析结果www.example.com与查询的解析结果相同othersite.com

在您的示例中,这将使访问者仍处于http://www.example.com/,连接到与名称 关联的任何 IP 地址othersite.com

如果托管的 Web 服务器othersite.com不喜欢Host: www.example.comHTTP 标头,它很可能会返回错误或某些默认页面,而不是它所服务的内容Host: othersite.com