域名IP地址为www,非www为规范URL

编程入门 行业动态 更新时间:2024-10-21 07:36:30
本文介绍了域名IP地址为www,非www为规范URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为了处理规范网址,最好的做法是做一个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
配置2(A记录)

主机|类型|数据 ----------------- + ------- + ------------- mydomain。 com | A | 58.162.62.34 www.mydomain | A | 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.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 | 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
Configuration 2 (A records)

Host | Type | Data -----------------+-------+------------- mydomain | A | 58.162.62.34 www.mydomain | A | 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;DR

You 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

本文发布于:2023-11-01 12:43:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地址   域名   URL   IP   www

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!