SEO best practises - Canonical urls for pages in Multisite environment

Read time: 10 min

This blog post puts the start of a series of SEO best practises.

Canonical URLs are one of the crucial advancements in SEO practices. In many cases you may want to display the same content via one or more pages. This is called a duplicate content. However it's very difficult for a search engine to make a determination which value is correct if it comes the same or extremely similar piece of content with different URLs. Also search engines like Google have decided that they don't like duplicate content and pages with duplicate content don't rank well. For that purpose a canonical URL is used. It represents a tag that is part of the HTML header of a web page, in the same section where the title and meta description tags are rendered. Here's an example of a link tag: 

<link rel="canonical" href="http://canonical-url-goes-here" />

The Canonical URL tag attribute is similar in many ways to a 301 redirect from an SEO perspective. In essence, you're telling the engines that multiple pages should be considered as one (which a 301 does), without actually redirecting visitors to the new URL.

Sitefinity already provides a canonical URLs implementation for the following widgets: 

* News

* Event

* Blog post

* Image gallery

* Video gallery

* Download list

* List items

* Products list 

For more information, see Enabling and disabling Canonical URLs service. 

 Imagine that your pages are using content blocks to store content. Also you wish to keep versions of the content by adding new site and copying all the pages from the previous one. The problem here is that the same content will be accessed by different URLs - classical SEO problem. Here you will have to add a canonical URL for the pages choosing which is your default version. Follow the steps below to add canonical URLs to pages: 

  1. Open your SitefinityWebApp in Visual Studio and add new web user control. 

  2. Name the control CanonicalMetaTagSetter.ascx

  3. Open the code-behind and put the following code inside:

    protected void Page_Load(object sender, EventArgs e)
                //if the url contains a virtual directory, the application virtual path will be replaced
                //by the url of the current (default) site.
                string defaultSiteUrl = Telerik.Sitefinity.Multisite.MultisiteManager.GetManager().GetSites().FirstOrDefault(a => a.IsDefault).LiveUrl;
                var liveUrl = SystemManager.CurrentContext.CurrentSite.LiveUrl;
                var requestUrl = SystemManager.CurrentHttpContext.Request.Url.AbsoluteUri;
                string canonicalUrl = requestUrl;
                if (!liveUrl.Equals(defaultSiteUrl))
                    canonicalUrl = requestUrl.Replace(liveUrl, defaultSiteUrl);
            /// <summary>
            /// Sets the canonical meta tag.
            /// </summary>
            /// <param name="href">The href.</param>
            private void SetCanonicalMetaTag(string href)
                HtmlLink canonicalLink = new HtmlLink();
                canonicalLink.Attributes.Add("rel", CanonicalMetaTagSetter.CANONICAL);
                canonicalLink.Attributes.Add("href", href);
            private const string CANONICAL = "canonical";

The code above replaces the liveUrl of the default site with the currently opened site and creates HtmlLink element with the canonical (default) url.

The result will be: 

Now you can build the application. 

4. Register your control in Sitefinity. For more information, see Registering a new widget in Sitefinity.  

5. Go to the Page Template that is used by your pages and add the user control in it. 

As a result each time you request a page from any of the sites, a link tag will be rendered inside with href with value equal to the canonical URL that you set in the CanonicalMetaTagSetter.  


Veronica Milcheva

I am a passionate Sitefinity blogger, developer and consultant. In my spare time I enjoy running and listening to music. My personal quote: There's no tough problem, just not enough coffee :)

Sofia, Bulgaria