HI we are trying to add a canonical tag into our site (which uses episerver) for all pages as below -
<link rel="canonical" href="http://www.mysite.com/mens/Products" />
<link rel="canonical" href="http://
How ever when I add the tag on my page and view the source it only shows the relative path. So if the above tag is added on the page having url - www.mysite.com/mens/Products - it will appear as
<link rel="canonical" href="../Products" />
<link rel="canonical" href="..
The reason for this is that if the first section of any link matches the URL entered in the browser it srtirps it out and shows a relative path.
This however causes a problem for us as the important section inthe URL which defines that it is the product list page for the "Mens" category has been stripped out.
Could you please let us know how to display full urls when they match the url entered in the browser.
Please note that when I create a new website not using episerver and add the link to the page it appear in full and not relative.
Here's an extension method for getting the pages external URL (taken from EPiCode.Extensions).
/// Get the pages external URL
/// The pages external URL
public static string GetExternalUrl(this PageData page)
string result = string.Empty;
if (page.PageLink != null && page.PageLink.ID > 0)
var url = new UrlBuilder(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + page.LinkURL);
Global.UrlRewriteProvider.ConvertToExternal(url, null, Encoding.UTF8);
result = url.ToString();
result = url.ToString();
The issue we have is not in retrieving the full URL but actually displaying the full URL it in the page itself. So after using the method described above we are returned a URL like below
Then when we render it in the canonical tag as detailed below:
<link rel="canonical" href="<%= GetExternalUrl(this.Page) %> " />
It appears as follows in the page source:
<link rel="canonical" href="../Categories” />
We need it to appear as follows:
<link rel="canonical" href="www.mysite.com/Women/Categories" />
We think then when the page is being processed by EPiServer that as the URL of the page in the browser and the URL of the href matches exactly it shows a relative path instead of the full path. Is there any way of overcoming this behaviour?
Hmm this sounds very weird.. What version of EPiServer CMS are you running? Could you try it on a clean installation?