Specify your preferred external URL in EPiServer

Posted on November 7, 2009 by Frederik Vig in EPiServer

Here’s a little SEO tip – search engines give you a penalty for having duplicate content. Duplicate content can be different urls going to the same content, eg:

  • http://www.example.com/tags/episerver/sort=newest
  • http://www.example.com/tags/episerver/sort=oldest
  • http://www.example.com/tags/episerver/

These are all pointing to the same content. The problem with this is that your PageRank or link popularity will decrease because of this. Fortunately it is very easy to specify a preferred URL that Search Engines will use. You simply add a HTML link element, with the rel attribute set to canonical, and the href to the preferred URL.

<link rel="canonical" href="http://www.example.com/tags/episerver" />

In EPiServer we also have a simple way of setting a simple address to a page. Under Advanced Information and Simple address for this page.
EPiServer edit mode - Advanced Information
Now we only need to add a little code to get the value, generate the HTML link element and add it to the HTML head element. If you’re using code based on the Public Templates, this goes in the Header.ascx and under the CreateMetaData method.

if (IsValue("PageExternalURL"))
	var canonicalLink = new HtmlGenericControl("link");
	canonicalLink.Attributes.Add("rel", "canonical");
	canonicalLink.Attributes.Add("href", EPiServer.Configuration.Settings.Instance.SiteUrl + CurrentPage["PageExternalURL"].ToString());

The key here is the PageExternalURL property, which is an EPiServer default property (See the SDK for more). You could of course create your own unique property for this.

This will render the following markup:

<link rel="canonical" href="http://www.example.com/MyPage" />

Note that you don’t need to include EPiServer.Configuration.Settings.Instance.SiteUrl (http://www.example.com), only CurrentPage[“PageExternalURL”].ToString() (/Mypage) will work fine as well. But I prefer to include the main domain name for the site (from the web.config setting, siteUrl).

For more information see this blog post from Google.

Related Posts: