Try our conversational search powered by Generative AI!

Absolute URL when using Html.CanonicalLink()

Ted
Ted
Vote:
 

The Html.CanonicalLink() HTML helper is, well, helpful. :)

However, it (always?) renders a relative URL.

Although both relative and absolute URLs are supported, according to Google absolute URLs are preferred: https://support.google.com/webmasters/answer/139066?hl=en&rd=1

Especially since we might have multiple domains pointing to the same site, for example if edit mode is accessed through a different domain, or if both http and https is supported, etc.

I tried looking at the internals of CanonicalLink(), but the CanonicalLinkRenderer class is internal, and I couldn't see a simple way of making CanonicalLink() render an absolute URL instead.

Of course we can roll our own helper method (and we have), but it just seems like the better choice would be to use the built-in one in Episerver.

So, in short: any ideas on how to make CanonicalLink() render absolute canonical tags?

#147284
Apr 09, 2016 11:01
Vote:
 

Hi,

I've had this discussion before... hehe. For me it also makes sense to ALWAYS return an absolute URL. It's actually stripped out if the current request's host is matching the primary host defined in the site definitions. Please see my post here about getting an absolute URL, which you can use in your canonical meta element, and also the comment from Henrik. http://dodavinkeln.se/post/how-to-get-the-external-url-to-content

#147287
Apr 10, 2016 13:56
Vote:
 
<p>Can we have an option to render the URL as absolute? Google guidelines say it shoud be absolute:&nbsp;https://support.google.com/webmasters/answer/139066?hl=en#2</p> <p></p>
#148848
May 25, 2016 5:04
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.