I am just trying to verify the best way to add a self-referening canonical tag to a multilingual Sitecore site.
If I use something like:
<link rel="canonical" href="@Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item)" />
Do I need to put in any checks for language, aliases, or localization?
For examples if I had a page:
www.mywebsite.com/en/organizations
I would want the tag to be:
<link rel="canonical" href="http://www.mywebsite/en/organizations" />
Even if that page had an alias -> so if www.mywebsite.com
/orgs was an alias for http://www.mywebsite/en/organizations
, the same canonical tag:
<link rel="canonical" href="http://www.mywebsite/en/organizations" />
would be rendered to the page.
Or if I turned this into an AMP page, it would still point back to the original (canonical) URL.
Also, I wonder about the regional sites since I could have this page on a UK site but localized:
www.mywebsite.com/en-GB/organi
sations
<- note the 's'
So the correct canonical tag would be:
<link rel="canonical" href="http://www.mywebsite/en-GB/organi**s**ations" />
However, I know that Sitecore will still show a page if there is a US English version and the US non-localized URL is requested. For example, if I accessed this URL:
www.mywebsite.com/en-GB/organi
zations
<- note the 'z'
It won't 404 which is perfectly fine, but I would still want the canonical tag to be the correct localized URL:
<link rel="canonical" href="http://www.mywebsite/en-GB/organi
sations" />
<- Again note the 's' which is the correct canonical version of this page.
Basically I just want to always return the correct, language/region-aware URL despite any edge cases.
Any insight is much appreciated!