EPiServer SEO: Reduce Duplicate Content Links

Google and other search engines does not like duplicate content. The reason is that the page’s reputation (or page rank) is calculated from incoming internal and external links. If you have more links leading to the same page the reputation will be split between the URLs.

One an EPiServer site with English as default language in siteHosts-tag the start page can usually be reached by the following two URLs. (Read more about siteHosts, Globalization and how to set the default language for a domain.)

  1. www.mydomain.com/
  2. www.mydomain.com/en/

EPiServer’s Friendly URL Rewriter adds “/en” to the beginning to select Language Branch if the internal URL contains the query parameter epslanguage.  So you can have a lot of both URLs on your site, both leading to the same page.

One recommended strategy to handle multiple URLs to the same page is to use 301 Redirection but that is a topic for another blog post (Ted Nyberg had a good post about this some time ago). In this post I want to show you how easy it is to tweak EPiServer’s Friendly URL Rewriting to eliminate duplicate URLs caused by language.

Example of how to tweak EPiServer’s Friendly Url Rewriter

public class Global : EPiServer.Global
{
    protected void Application_Start(Object sender, EventArgs e)
    {
        EPiServer.Web.UrlRewriteModule.HttpRewriteInit += UrlRewriteModule_HttpRewriteInit;
    }

    /// <summary>
    /// This adds the hooks to the UrlRewriter instance
    /// </summary>
    private void UrlRewriteModule_HttpRewriteInit(object sender, UrlRewriteEventArgs e)
    {
        UrlRewriteModuleBase module = sender as UrlRewriteModuleBase;
        if (module != null)
        {
            module.HtmlAddingRewriteToExternalFilter += module_HtmlAddingRewriteToExternalFilter;
            UrlRewriteProvider.ConvertedToExternal += UrlRewriteProvider_ConvertedToExternal;
        }
    }

    /// <summary> 

    /// Remove language from path if it is the default for the hostname.

    /// </summary> 

    private void UrlRewriteProvider_ConvertedToExternal(object sender, UrlRewriteEventArgs e)
    {
        if (e.IsModified)
        {
            string lang = LanguageSelection.GetLanguageFromHost();
            if (e.Url.Path.StartsWith( '/' + lang + '/'))
            {
                e.Url.Path = e.Url.Path.Substring(lang.Length + 1);
            }
        }
    }

    /// <summary>
    /// Prevent Rewrite To External for Trace.axd and 

    /// other locations I do not want EPiServer to interfere with.
    /// </summary>
    private void module_HtmlAddingRewriteToExternalFilter(object sender, UrlRewriteEventArgs e)
    {
        string path = e.Url.Path.ToLowerInvariant();
        e.Cancel = e.Cancel || path.EndsWith("trace.axd") || path.StartsWith("/MyWebApp")

    }
}