域名IP地址为www,非www为规范URL [英] Domain IP address for www and non-www for Canonical URL

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

问题描述



为了处理规范网址,最好的做法是做一个301重定向或更好地为www和非www域名拥有相同的IP地址?例如:



规范网址/域名需要 http://mydomain.com

 域名|记录
------------------------------------
mydomain.com | 58.162.62.34
www.mydomain.com | 58.162.62.34

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



或者更好。

  Domain |记录
------------------------------------
mydomain.com | 58.162.62.34
* www.mydomain.com 301重定向到mydomain.com


解决方案

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



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



配置1(CNAME记录)



 主机|类型|数据
----------------- + ------- + -------------
mydomain。 com | A | 58.162.62.34
www.mydomain.com | CNAME | mydomain.com




  • nslookup mydomain.com 解析为 58.162.62.34

  • nslookup www.mydomain.com 解析为 58.162.62.34



配置2(A记录)



 主机|类型|数据
----------------- + ------- + -------------
mydomain。 com | A | 58.162.62.34
www.mydomain.com | A | 58.162.62.34




  • nslookup mydomain.com 解析为 58.162.62.34

  • nslookup www.mydomain.com 解析为 58.162.62.34



在这两种情况下,你的规范域名,您的 www 子域名解析为 58.162.62.34 。但是,您的HTTP服务器唯一能识别的是它收到 mydomain.com www.mydomain.com 在相同的IP地址。但是它不知道你是否使用了 A CNAME 记录。



TL; DR



您必须使用HTTP 301重定向才能执行规范的 mydomain.com 在HTTP请求中。但这与您的DNS配置无关。


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?

For example:

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

Domain           | A Record
------------------------------------
mydomain.com     | 58.162.62.34
www.mydomain.com | 58.162.62.34

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.

Or is this better.

Domain           | A Record
------------------------------------
mydomain.com     | 58.162.62.34
*  www.mydomain.com 301 redirect to mydomain.com

解决方案

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.

Let's look at two different DNS configurations:

Configuration 1 (CNAME record)

Host             | Type  | Data
-----------------+-------+-------------
mydomain.com     | A     | 58.162.62.34
www.mydomain.com | CNAME | mydomain.com

  • nslookup mydomain.com resolves to 58.162.62.34
  • nslookup www.mydomain.com resolves to 58.162.62.34

Configuration 2 (A records)

Host             | Type  | Data
-----------------+-------+-------------
mydomain.com     | A     | 58.162.62.34
www.mydomain.com | A     | 58.162.62.34

  • nslookup mydomain.com resolves to 58.162.62.34
  • nslookup www.mydomain.com resolves to 58.162.62.34

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

TL;DR

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

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

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