Domain IP address for www and non-www for Canonical URL

老子叫甜甜 提交于 2019-11-28 16:39:25

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.

You may try redirect.center. Its redirects domains using DNS only.
So it will fulfill your DNS configurations:

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

set your dns record to:

CNAME | www | mydomain.com.opts-https.redirect.center

Note:
The .opts-https. parameter redirect to https domain
If you use only http domain then use .opts-uri.

In DNS the canonical name record is pointing to the "one true DNS entry". The end result is that DNSName1 has the same IP address as DNSName2.

Comprehension is complicated by the fact that the CNAME is not the canonical name. The CName Record points to the canonical name. (The canonical name is the A record).

Canonical link: For search engines the canonical link in the html header of a page specifies the "one true page". You can get to multiple pages but you use the canonical link to tell the search engine that this page is the same as the other page. Doing this makes the search engine happy that you are not gaming the system by pretending to provide more content where it is only duplication. It only indexes it once.

301 (http) redirects: For search engines this says that page x is now replaced by page y and all the search ranking can be transferred to page y. If it is a "cosmetic" domain-name-standardisation it also tells the search engine to only index one page and is again a way to show that you're not trying to trick the search engine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!