Try our conversational search powered by Generative AI!

Canonical Tags - Full Path Required

Vote:
 

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" />

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" />

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.

Kind Regards

 

#38141
Mar 31, 2010 9:52
Vote:
 

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);

		if (UrlRewriteProvider.IsFurlEnabled)
		{
			Global.UrlRewriteProvider.ConvertToExternal(url, null, Encoding.UTF8);
			result = url.ToString();
		}
		else
		{
			result = url.ToString();
		}
	}

	return result;
}
#38147
Mar 31, 2010 10:43
Vote:
 

Hi,

 

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

www.mysite.com/Women/Categories

 

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?

 

Thanks

#38743
Apr 20, 2010 16:59
Vote:
 

Hmm this sounds very weird.. What version of EPiServer CMS are you running? Could you try it on a clean installation?

Frederik

#38744
Apr 20, 2010 19:01
* 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.