The script you posted only makes sure the url always uses "www". A canonical url is dependent on the client and that it understands the canonical tag. A 301 will forcefully redirect any request from non-www to www at the server level (IIS).
Googles recomendation:
While the canonical link element has its benefits, Matt Cutts, the
head of Google's webspam team, has claimed that the search engine
prefers the use of 301 redirects. Cutts claims the preference for
redirects is because Google's spiders can choose to ignore a canonical
link element if they feel it is more beneficial to do so.[8]
https://en.wikipedia.org/wiki/Canonicallinkelement
(for some reason the forum breaks the link, just check the wikipedia article for "Canonical link element")
Canonical URL
Hi all,
Just a quick note to mention that the code on this page didn't work for me in Umbraco 7.3.1 : https://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/canonicalurl/
Here's some revised code that does work in Umbraco 7.3.1 though
Hopefully that will help anyone who was looking how to do this as I was!
I would actually suggest adding a 301 Redirect instead in Umbraco's UrlRewriting.config.
How does adding a 301 redirect provide a canonical link variable ?
Unless I'm missing something I can't see how what you posted relates.
Hi Paul,
The script you posted only makes sure the url always uses "www". A canonical url is dependent on the client and that it understands the canonical tag. A 301 will forcefully redirect any request from non-www to www at the server level (IIS).
Googles recomendation:
https://en.wikipedia.org/wiki/Canonicallinkelement (for some reason the forum breaks the link, just check the wikipedia article for "Canonical link element")
Thanks Per, I wasn't aware you could do it like that (using 301 redirects).
Many thanks :-)
is working on a reply...