Saturday, 12 July 2014

Impact of Sitecore Aliases on SEO

Leave a Comment
Today I’ve noticed a post in Sitecore SDN forum regarding impact of Sitecore Aliases on SEO. While answering to the post; I thought it'd be better to turn it into a Blog post with more detail. :)

From SEO point of view, using aliases in Sitecore is not good option. The main reason is multiple URLs will be created for a single page URL. This in turn shows up in Google search engine as two pages and will consider as duplicate content. Search engines try to index pages with distinct and unique content. Duplicate content affects adversely the hits for the page in the results rankings. So it will be better to avoid aliases in Sitecore whenever possible.

No redirect (no 301 or 302 HTTP status code) happens when you are using aliases in Sitecore. You can monitor HTTP status code and web traffic using Fiddler.  Suppose you’ve created aliases for a Sitecore item /sitecore/content/Home/sample/sample1/sample2 as sampleitem. If you open then you will see HTTP status code as 200 and if you open www. then also you will see HTTP status code as 200 which means that we are having two URLs which is generation same content (duplicate content).

Set canonical URL link into the head of the page whenever you are using aliases in Sitecore. Using canonical URLs to improve link and ranking signals for content available through multiple URL structures is recommended practice.

How to implement Canonical URL link in Sitecore:

Override AliasResolver processor in HttpRequest pipeline and write custom logic to handle aliases and generate canonical link. In web.config you will see below line related to AliasResolver processor:
<processor type="Sitecore.Pipelines.HttpRequest.AliasResolver, Sitecore.Kernel" />
Below is the custom code for CustomAliasResolver:
using Sitecore;
using Sitecore.Links;
using Sitecore.Pipelines.HttpRequest;
using System.Web;

namespace Sitecore.Ramblings
    public class CustomAliasResolver : Sitecore.Pipelines.HttpRequest.AliasResolver
        public CustomAliasResolver()

        public override void Process(HttpRequestArgs args)
            if (Context.Item != null)
                string href = "{0}://{1}{2}";
                args.Context.Items["CanonicalUrl"] = string.Format(href, HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, LinkManager.GetItemUrl(Context.Item));
Modify web.config as below:
<!--<processor type="Sitecore.Pipelines.HttpRequest.AliasResolver, Sitecore.Kernel" />-->
<processor type="Sitecore.Ramblings.CustomAliasResolver, SitecoreRamblings" />
The type format is “<namespace>.<class name>, <assembly name>”. For example: Sitecore.Ramblings is namespace, CustomAliasResolver is class name and SitecoreRamblings is assembly name.

Now in the header control or in layout of your website check whether HttpContext.Current.Items["CanonicalUrl"] is not null and set canonical URL into the head of page. Below is the sample code to set canonical URL in layout of Sitecore MVC website.
@if (Context.ApplicationInstance.Context.Items["CanonicalUrl"] != null)
 <link rel="canonical" href="@Context.ApplicationInstance.Context.Items["CanonicalUrl"].ToString()" />
Comments and suggestions are most welcome. Happy coding! 


Post a Comment