为了处理规范网址,最好的做法是做一个301重定向或更好地为www和非www域名拥有相同的IP地址?例如:
规范网址/域名需要 mydomain
域名|记录 ------------------------------------ mydomain | 58.162.62.34 www.mydomain | 58.162.62.34我知道人们可能拥有www的CNAME记录(别名,因为CNAME被称为规范名称);不确定这是否是使用相同IP地址的最佳做法。
或者更好。
Domain |记录 ------------------------------------ mydomain | 58.162.62.34 * www.mydomain 301重定向到mydomain解决方案
您描述的机制( A 和 CNAME 记录与 301 重定向)是两种不同协议(DNS和HTTP)的一部分。 A 和 CNAME 记录与HTTP服务器为不同请求服务的网站无关。
我们来看看两种不同的DNS配置:
配置1(CNAME记录) 主机|类型|数据 ----------------- + ------- + ------------- mydomain。 com | A | 58.162.62.34 www.mydomain | CNAME | mydomain
- nslookup mydomain 解析为 58.162.62.34
- nslookup www.mydomain 解析为 58.162.62.34
- nslookup mydomain 解析为 58.162.62.34
- nslookup www.mydomain 解析为 58.162.62.34
在这两种情况下,你的规范域名,您的 www 子域名解析为 58.162.62.34 。但是,您的HTTP服务器唯一能识别的是它收到 mydomain 和 www.mydomain 在相同的IP地址。但是它不知道你是否使用了 A 或 CNAME 记录。
TL; DR您必须使用HTTP 301重定向才能执行规范的 mydomain 在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 mydomain
Domain | A Record ------------------------------------ mydomain | 58.162.62.34 www.mydomain | 58.162.62.34I 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 | 58.162.62.34 * www.mydomain 301 redirect to mydomain解决方案
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 | A | 58.162.62.34 www.mydomain | CNAME | mydomain
- nslookup mydomain resolves to 58.162.62.34
- nslookup www.mydomain resolves to 58.162.62.34
- nslookup mydomain resolves to 58.162.62.34
- nslookup www.mydomain 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 and www.mydomain on the same IP address. But it doesn't know whether you used A or CNAME records for that.
TL;DRYou have to use HTTP 301 redirects to enforce the canonical mydomain in HTTP requests. But that has nothing to do with your DNS configuration.
更多推荐
域名IP地址为www,非www为规范URL
发布评论