Thursday, May 16, 2024

Let’s talk about the Canonical label again. There are advantages to using it properly and disadvantages to using it incorrectly. You need to be careful when using it.

 1. Why have Canonical?


Let me talk about the conclusion first. The purpose of Canonical is to solve the problem of duplicate URLs. Note that Gefei is talking about duplicate URLs, not duplicate web pages.


The same web page may be accessible by multiple domain names. The most typical one is that both the www domain name and the naked domain name can be accessed, which results in a web page having multiple URLs.


If it is a subdirectory, it is possible that both /abc/ and /abc/index.html or /abc/index.php can be accessed, so a web page has more URLs.


This is not over yet, various parameters can be added after these URLs, which will also lead to more URLs appearing.


Ge Fei gives an example to give everyone a better understanding.


Assume that the domain name is gefei.vip and both www.gefei.vip and gefei.vip are resolved.


Note that Ge Fei is just used as an example here. The actual more standardized approach is to select one domain name as the main domain name, and then jump another domain name to this main domain name through 301.

For example, Gefei is accustomed to choosing gefei.vip as the main domain name, and then jumps www.gefei.vip 301 to gefei.vip.

Note that if it is a large website, in order to prevent cookie leakage, www.gefei.vip is generally used as the main domain name, and then 301 is used to jump to www.gefei.vip.


Assume that the directory is /shequn/ and the backend is written in php, that is, both /shequn/ and /shequn/index.php can be accessed.


Assume that both Zhang San and Li Si recommended the Gefei community on their websites, and both brought source parameters. The parameter names are different, one is ref=zs and the other is via=ls.


Then a total of the following URLs may be used:


https://gefei.vip/shequn/

https://www.gefei.vip/shequn/

https://gefei.vip/shequn/index.php

https://www.gefei.vip/shequn/index.php

https://gefei.vip/shequn/index.php?ref=zs

https://www.gefei.vip/shequn/?via=ls

There could be more…


Ge Fei only listed some of the situations above, and there may actually be more.


These URLs that look different are actually the homepage of the community, and the html returned is the same.


Then in the eyes of search engines, it will be very strange why there are so many duplicate web pages.


Note that Ge Fei used "duplicate web pages" here, but used "duplicate URLs" in the previous article. This is actually a different perspective.


In our own eyes, we know that these URLs are actually different URLs of the same web page, so they are "duplicate URLs", but in the eyes of search engines, these are some "duplicate web pages".


Ge Fei will expand here. In addition to the above reasons, which will cause duplicate web pages, if your code is front-end rendering, it will also cause duplicate web pages. For details, you can read this article "[Ge Fei SEO Tutorial] If you don't want the ones given by Google Free traffic, just use front-end rendering."


In order to allow webmasters to tell search engines the most standardized URL, search engines such as Google began to use the Canonical tag.


2. What is Canonical and what is it used for?


Let’s take the example given by Ge Fei above. The standard and unique URL I want to use is:

https://gefei.vip/shequn/


Then you can add the following line of code to the head of the web page html:


<link rel="canonical" href="https://gefei.vip/shequn/">


In this way, no matter which URL others use to access the community homepage, Canonical remains the same:

https://gefei.vip/shequn/


So the correct usage of Canonical is to specify the canonical URL of each web page.


3. How to write Canonical in multiple languages


Assume that your website has multiple languages, such as supporting both Chinese and English, and the URLs are:


Chinese

https://gefei.vip/shequn/

English

https://gefei.vip/en/shequn/


At this time, you should pay attention. In the html of the English page, Canonical should be written like this:


<link rel="canonical" href="https://gefei.vip/en/shequn/">


see it?


Canonical needs to faithfully reflect the real URL of the current page.


Never write down the same URL regardless of the language.


Ge Fei has also seen some people write Canonical on the homepage of any website address. This is also wrong. It is a mistake caused by a lack of understanding of Canonical.


4. What are the benefits of Canonical?


Let’s take the example above. Both Zhang San and Li Si have given external links. Although the link addresses given are different, if we set the correct Canonical in the page, then the search engine will be able to link these different URLs. The weights are aggregated into the URL specified by Canonical.

No comments:

Post a Comment