www 的域 IP 地址和规范 URL 的非 www 的域 IP 地址 [英] Domain IP address for www and non-www for Canonical URL

查看:22
本文介绍了www 的域 IP 地址和规范 URL 的非 www 的域 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要处理规范 URL,最佳做法是进行 301 重定向还是更好地为 www 和非 www 域使用相同的 IP 地址?

To handle Canonical URL is it best practice to do a 301 redirect or better to have the same IP Address for both www and non www domain?

例如:

所需的规范 URL/域是 http://example.com

Canonical URL/domain wanted is http://example.com

Domain           | A Record
------------------------------------
example.com      | 192.0.2.34
www.example.com  | 192.0.2.34

我知道人们可能有 www 的 CNAME 记录(别名,鉴于 CNAME 被称为规范名称);与使用相同的 IP 地址相比,不确定这是否是最佳做法.

I understand people may have a CNAME record for www (alias, given that CNAME is called Canonical Name); unsure if this is best practice compared to using the same IP address.

或者这样更好.

Domain           | A Record
------------------------------------
example.com     | 192.0.2.34
*  www.example.com 301 redirect to example.com

推荐答案

你描述的机制(ACNAME 记录 vs. 301重定向)是两种不同协议(DNS 和 HTTP)的一部分.ACNAME 记录与您的 HTTP 服务器为不同请求服务的站点无关.

The mechanisms you describe (A and CNAME records vs. 301 redirects) are part of two different protocols (DNS and HTTP). A and CNAME records have nothing to do with which site your HTTP server serves for different requests.

让我们看看两种不同的 DNS 配置:

Let's look at two different DNS configurations:

Host             | Type  | Data
-----------------+-------+-------------
example.com      | A     | 192.0.2.34
www.example.com  | CNAME | example.com

  • nslookup example.com 解析为 192.0.2.34
  • nslookup www.example.com 解析为 192.0.2.34
    • nslookup example.com resolves to 192.0.2.34
    • nslookup www.example.com resolves to 192.0.2.34
    • Host             | Type  | Data
      -----------------+-------+-------------
      example.com      | A     | 192.0.2.34
      www.example.com  | A     | 192.0.2.34
      

      • nslookup example.com 解析为 192.0.2.34
      • nslookup www.example.com 解析为 192.0.2.34
        • nslookup example.com resolves to 192.0.2.34
        • nslookup www.example.com resolves to 192.0.2.34
        • 在这两种情况下,您的规范域和您的 www 子域都解析为 192.0.2.34.但是,您的 HTTP 服务器唯一会识别的是它在同一 IP 地址上接收对 example.comwww.example.com 的请求.但它不知道您为此使用了 A 还是 CNAME 记录.

          In both cases your canonical domain and your www subdomain resolve to 192.0.2.34. However, the only thing your HTTP server will recognize is that it receives requests for both example.com and www.example.com on the same IP address. But it doesn't know whether you used A or CNAME records for that.

          您必须使用 HTTP 301 重定向来强制执行 HTTP 请求中的规范 example.com.但这与您的 DNS 配置无关.

          You have to use HTTP 301 redirects to enforce the canonical example.com in HTTP requests. But that has nothing to do with your DNS configuration.

          这篇关于www 的域 IP 地址和规范 URL 的非 www 的域 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆