Return to doc.sitecore.com

Friendlier Marketing URLs for Sitecore 6
Prev Next

Author: Oleg Burov
Posted: 8/17/2009 12:00:00 PM

Note: information below is valid for Sitecore 6.0 and Sitecore 6.1 solutions. Corresponding techniques are a subject to change in future Sitecore releases.

This document describes quick instructions on how to set up Sitecore to generate friendlier marketing URLs excluding the default ASPX extension.
As example, instead of http://mysite.com/products.html URL it should be possible to generate http://mysite.com/products.html or http://mysite.com/products URL.
URL extension will also be configurable for a specific web site, meaning that one logical Sitecore site can use HTML extension for links, while other ones use ASPX.
The recommended approach in this case would be the following:

  1. Configure IIS 404 error handler to redirect to "/default.html" URL. Instruction on how this is done can be found in the following article:
    http://sdn.sitecore.net/reference/sitecore 6/dynamic links.html
  2. Implement a class that overrides the default Sitecore.Links.LinkProvider class from Sitecore.Kernel assembly. A code example can be found below:
    public class CustomLinkProvider : Sitecore.Links.LinkProvider  
    {
       public override string GetItemUrl(Item item, UrlOptions options)
       {
          string itemUrl = base.GetItemUrl(item, options);     
          string urlExtension = options.Site.Properties["urlExtension"] ?? string.Empty ;
          if (urlExtension.Equals("{empty}"))
          {
             itemUrl = itemUrl.Replace(".html", string.Empty);
          }
          else if (!urlExtension.Equals(string.Empty))
          {
             itemUrl = itemUrl.Replace(".html", "." + urlExtension);
          }
          return itemUrl;
       }
    }
  3. Compile an assembly and put it under \bin folder of your solution.
  4. Update the "type" attribute of the "/configuration/sitecore/linkManager/providers/add" element with name "sitecore" in web.config to use your class signature:
    <add name="sitecore" type="MyCompany.CustomLinkProvider, MyAssembly" ... />
    Note: addAspxExtension attribute must be set to true.
  5. Make sure you add extension you want to use for your page URLs to the list of allowed extensions for "FilterUrlExtensions" processor of "preprocessRequest" pipeline.
  6. Add "urlExtension" attribute to the necessary "/configuration/sitecore/sites/site" element in web.config in the following way:
    <site name="website" urlExtension="html" .../>
    if you want URLs to be generated with e.g. HTML extension for the specified Sitecore web site, and
    site name="website" urlExtension="{empty}" .../>
    if you want URLs to be generated without extension for the specified Sitecore web site.
    Note: you should apply "urlExtension" attribute only for public facing web sites. Using it for "shell" site may cause issues with Sitecore client functionality.

More information about Dynamic Links in Sitecore 6 can be found in the following article:
http://sdn.sitecore.net/reference/sitecore 6/dynamic links.html


Prev Next