What Is rel=canonical And How Do I Use It?
The canonical page is commonly known as the preferred page when there are a number of pages with similar content that could be misinterpreted as a copy.
Firstly you need to set the preferred version of your website. Google treat www and non-www as two separate URL’s. That can be done in Google Search Console by adding and verifying both versions.
Using rel=canonical In The <head> Section Of Your Document
To use the <link> element with the attribute rel=canonical in the <head> section of your document you would need access to your page codes, or you can use a plugin such as Yoast SEO. This would tell Google which is the preferred version of a set of similar pages.
Example Of rel=canonical
<link rel=”canonical” href=”http://www.yourpage.com” />
In this example, www.yourpage.com is the preferred page. The above canonical would then be inserted into the <head> section of similar pages, which point to the original page. And it would be inserted into the <head> of the preferred page pointing to itself.
rel=canonical is useful for HTML content but cannot be added to PDF’s and other files. For PDF you would need to be able to configure your server.
Example Of A PDF rel=canonical
Link: <http://www.yourpage.pdf>; rel=”canonical”
Always remembering that re=canonical is only seen as a suggestion. Google will determine which URL contains the copy content and thereafter they will determine the most relevant page to display in search.
rel=canonical can also be used when migrating to a new domain if 301 redirect is not possible