here and there during my Sitecore development

How I make SEO-friendly Sitecore URLs?

In the past, the URLs of your web pages might not be SEO friendly or not self-described enough.  They might look like:

Now with Sitecore, the URL is generated by the structure of items you put in place in the content tree (by default).  If your “Careers” item in Sitecore content tree looks like this:

    • Sitecore
      • Content
        • Home
          • Company
            • About Our Company
              • History
              • Careers ***

The URL of your Careers page will look like this:

www.yourcompany.com/Company/About Our Company/Careers.aspx or
www.yourcompany.com/Company/About%20Our%20Company/Careers.aspx

Note that “%20” is a space character.

Now you notice that the URL is now better that the old style URLs that contain ID or querystrings.

To make it more friendly, we can easily replace space in Sitecore web.config

<encodeNameReplacements>
   <replace mode="on" find="&amp;" replaceWith=",-a-," />
   <replace mode="on" find="?" replaceWith=",-q-," />
   <replace mode="on" find="/" replaceWith=",-s-," />
   <replace mode="on" find="*" replaceWith=",-w-," />
   <replace mode="on" find="." replaceWith=",-d-," />
   <replace mode="on" find=":" replaceWith=",-c-," />
   <replace mode="on" find=" " replaceWith="-" />  <!-- to replace space with dash -->
   <replace mode="on" find="_" replaceWith="-" />  <!-- to replace underscore with dash -->
</encodeNameReplacements>

I added 2 lines to replace both space and underscore with dash

Now the URL of your Careers page should look like this:
www.yourcompany.com/Company/About-Our-Company/Careers.aspx

Take another step, what if you want to remove “.aspx”?  It’s easy…

  1. Change addAspxExtension attribute in web.config to false
    <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false" />
    
  2. You might need to add wildcard script mapping in IIS

Now the URL of your Career page should look better:
www.yourcompany.com/Company/About-Our-Company/Careers

Last, but not least.  Someone said case difference may mean different pages and that case Google would index them separately.  I’m not sure if this is true but the best practice is to have one version of the page (I’d recommend it be the lowercase).  Follow these steps to generate lowercase URLs:Create a new class that overrides Sitecore.Links.LinkProvider class

  1. Create a new class that overrides Sitecore.Links.LinkProvider class
    namespace YourNamespace.Classes.Manager
    {
       // this class override the SitecoreLinkProvider so that the returned URLs will be all lowercase.
       public class CustomFriendlyLinkManager : Sitecore.Links.LinkProvider
       {
          public override string GetItemUrl(Sitecore.Data.Items.Item item, Sitecore.Links.UrlOptions urlOptions)
          {
             urlOptions.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving;
             return base.GetItemUrl(item, urlOptions).ToLower();
          }
       }
    }
    
  2. In linkManager tag in web.config, replace the Sitecore LinkProvider with your custom Link Provider
    <linkManager defaultProvider="sitecore">
       <providers>
          <clear />
          <!-- comment this out and replace with custom link provider to return URLs with all lowercase -->
          <!--<add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false" />-->
          <add name="sitecore" type="YourNamespace.Classes.Manager.CustomFriendlyLinkManager , yourprojectname" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false" />
       </providers>
    </linkManager>
    

Now the URL of your Career page looks clean and awesome
www.yourcompany.com/company/about-our-company/careers

8 responses

  1. Nice material here. One issue with the space to dash replacement is that once you make that change, you can no longer use dashes in the item names and must stick with spaces. Sometimes clients like to name items with colons and since colons are not allowed, they use a dash in the place of a colon (for the item name). With this approach, they can’t use the dash either. Just something to note.

    August 31, 2011 at 1:11 PM

  2. Thank you for reiterating that Mark. I forgot to say I usually add dash into InvalidItemNameChars value=”\/:?"<>|[]-” as well to prevent the issue. However, when you install some Sitecore modules that contain item with dash, you might have to temporarily remove dash from the setting.

    September 1, 2011 at 3:54 PM

  3. Glenn

    Thank you, thank you, thank you, thank you!

    All super useful information! I was looking for an article like this a month or 2 ago. I’ve since found most of the solutions described here scattered through the web. But it’s great to see them all in one space.

    Mark’s comment is very important, if you use:

    then you really have to add the ‘-‘ to the InvalidItemNameChars to protect your content creators from breaking the pages they create.

    For lowercase transformation I found another solution described here:
    http://blog.navigationarts.com/seo-url-sitecore/

    Where instead of using a .NET code to transform the urls to lowercase you can just use:
    … etc for all letters

    It’s not as elegant and probably not as ‘proper’ as you solution but it works and is quicker to implement.

    November 14, 2011 at 10:32 PM

  4. Pingback: Enforcing lowercase URLs in Sitecore | Blogpoint

  5. Pingback: Enforcing lowercase URLs in Sitecore | Rickard Andersson

  6. Updated in Sitecore 6.6, you can use the new attribute lowercaseUrls=”false” in the LinkProvider. You don’t have to make lowercase from the custom LinkProvider

    July 30, 2013 at 8:59 PM

  7. You are so awesome! I do not suppose I’ve read anything like that before.

    So wonderful to discover someone with original thoughts on this issue.
    Seriously.. many thanks for starting this up. This web site is
    something that is needed on the internet, someone with some
    originality!

    September 19, 2013 at 8:38 PM

  8. Thanks for the post! I added the configuration and it does work with replace space in url with dash but sadly the links replaced are all broken it says cannot find the item. Am I missing something? Thanks!

    February 24, 2014 at 7:18 AM

Leave a reply to cool games online Cancel reply