Select version
v7.7 v7.6 v7.5 v7.3 v7.1 v7.0 v6.8 v6.7 v6.6 v6 v5 v4 v3 v2

Working with Nice URLs in Sitecore

When building your website and you're linking to categories or products, you want the link to please search engines (Google). uCommerce comes with a set of OOTB components for grabbing and modifying the URLs. But to be able to extend them in a proper way you'll need to consider a few things that needs to be in place for uCommerce and Sitecore to function properly.

This article will explain how:

  • uCommerce and Sitecore works together in order to present a product or category page
  • How to modify the behaviour of nice URLs for categories and products

There's two sides to the equation

Everything in Sitecore and uCommerce is context driven meaning that everytime you request a URL both Sitecore and uCommerce needs to be able to populate the right data. Since uCommerce integrates into Sitecore as a seperate system, Sitecore will have the responsibility to populate pages give the current item we're looking at right now. This means that if we want to display a URL like the following: we need to help sitecore a little bit as they do not know what to do with that URL.

How nice URLs work with uCommerce

When you're entering a URL in your browser that takes you to a uCommerce product page, say visiting one product on the demo store:

The URL above will help determine the context of the request for uCommerce as we can identify that this is a URL that belongs to uCommerce. Not from the human readable part of the URL "black-white-wonderland-mood-slim-fit-signature-shirt-limited-edition" which is actually only for google, but from the last bit of the URL that contains: "/c-24/c-70/p-105". That part will help uCommerce setup the right context. Based on Regular expresions we can map this to a uCommerce request. Based on that we know what catalog, category and/or product we're browsing. The URLs comes in different versions depending on the context of the user as products can be visited across different catalogs and categories.

Url structure

As described above the context of the user will help determine the URL for the request. This means that URLs for a product will change depending on how they visit the product. The URL will always be based on display names for the different items supplied for the URL. The URLs will be build using the Hiearcy of the data in uCommerce.


Requesting a product from the Catalog 'Demo Catalog' under the category 'Formal' will produce the following URL:


Where the different slugs are:


Under the covers this is the exact same thing as asking for a url with querystring parameters - just presented a little nicer. For example the url above is more or less equivalent to the URL below as the url describes the context:

Data driven pages

To have a full funtioning data driven page in Sitecore and uCommerce you need to either:

  • have a Dedicated category/product page ** Needs an item in the Sitecore Content tree ** Layouts set on the category/product page letting Sitecore scaffold the page ** Query string parameters for catalog items in the uCommerce Context APIs found under 'Ucommerce.Runtime'

  • Use the data provider ** Layout directly on uCommerce item in Content editor ** Hook in to the Sitecore httpRequestBegin pipeline to Resolve the right Item ** Nice URLs using uCommerce APIs

When requesting our URL from before we need to be able to setup the right context for what we're looking at. The URL works well with uCommerce however Sitecore also needs to be saticfied before we can actually present the page for the user. Since Sitecore handles the resolution of templates it needs to be able to understand what we're actually looking at. Sitecore will not be able to map this to a page as it doesn't know about the URL. In the uCommerce+Sitecore integration you have the ability to work with category/product resolution in two different ways depending on your preferred setup:

  • A dedicated category page and product page – referred to as data driven pages (The URL will look similar to this: )
  • Resolve the product directly in our Data provider integration (The URL will look like similar to this:

Consider the structure below:


In that setup requesting /store/category.aspx will let Sitecore know what the item is. Now we just need to setup the uCommerce context using querystring parameters e.g the '?catalog=24&category=70&product=105' part from before. Sitecore and uCommerce will be happy as both systems knows how to resolve the right context. Sitcore can map it to a content page and thus the presentation details and uCommerce can populate the CatalogContext based on the querystring. However it is not a very SEO friendly URL so your SEO guy will not be happy :-)

As uCommerce comes with a data provider integration (all uCommerce data is available inside Sitecore) we can leverage that to resolve the right data. As described above uCommerce will be happy with the following URL:

However Sitecore doesn't. But with Sitecore comes the ability to hook into the Request pipeline. uCommerce has done that and placed an ItemResolver that will resolve the right uCommerce item inside Sitecore. So instead of having a dedicated category or product page each of the items in uCommerce (categories or products) will be its own page. Since the data is available in Sitecore we just need to configure presentation details on those. When that is done Sitecore is happy as well and we will have a full functioning page where uCommerce can deliver the right content for the page presented by Sitecore.

Grabbing Nice URLs from the API

To grab URLs for the different items in uCommerce you need to visit UCommerce.Api.CatalogLibrary which contains the following methods:

    public static string GetNiceUrlForCatalog(ProductCatalog catalog);
    public static string GetNiceUrlForCategory(Category category, ProductCatalog catalog = null);
    string GetNiceUrlForProduct(Product product, Category category = null, ProductCatalog catalog = null);
    string GetNiceUrlForVariant(Product variant, Category category = null, ProductCatalog catalog = null);

Change the URL structure

If you're not happy with how the URLs look like for uCommerce items you need to:

  • Hook into the HttpRequestBegin pipeline of Sitecore to set the right item in Sitecore and populate each of the items in UCommerce.Runtime.CatalogContext
  • Override the default implementation of 'UCommerce.Catalog.IUrlService' implemented by 'UCommerce.Catalog.UrlService'
uCommerce Aps - Studsgade 29B - 8000 Aarhus C - Denmark
Phone +45 61 799 997 - Email uCommerce logo