How canonical URLs work
When multiple URLs exist for a single piece of content, the canonical URL is the definitive web address you want to be visited and indexed by bots and visitors looking for the content. A canonical URL is the one that should be considered to be the original, or the “canon”.
Other URLs for this content might exist because your website creates them automatically. For example, some CMSs will automatically create an ID-based slug for your page, in addition to the carefully-chosen slug you enter.
Or they might exist because you’ve intentionally created different versions of your page that contain the same content, such a mobile version or a printable version or even a version with a parameter-based filter or sort, each with its own web address.
You might also syndicate your content in order to boost its reach; it might appear on Medium or other sites that publish collections of articles.
All of these non-canonical pages should include code in their HTML <head> section that references the canonical URL of the content. This takes the following form:
<link rel="canonical" href="https://yoursite.com/your-canonical-page">
This doesn’t send traffic to the canonical URL, but it does tell search engines that the content should probably be indexed at the canonical URL, not at the page where it was found.