Improving uCommerce SEO: getting rid of different URLs leading to same page

uCommerce is a great e-commerce package, I'm running it on top of Umbraco. Other than the default framework, there's example store available for everybody. I believe many people build their e-commerce portals on top of that example code. It already have lots of good and useful things incorporated, including markup for products, nice urls, etc. It all adds up to the SEO, resulting in an edge above average online shop.

But there's serious flaw I found in default uCommerce pages links strategy. Here is how user friendly links are implemented in uCommerce. Config/UrlRewriting.config:

<urlrewritingnet xmlns="">
    <add name="DefaultCategoryProductRewrite" virtualUrl="(.*)/c-([0-9]+)/c-([0-9]+)/p-([0-9]+)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/catalog/product?catalog=$2&amp;category=$3&amp;product=$4" ignoreCase="true" xmlns="" />
    <add name="DefaultProductRewrite" virtualUrl="(.*)/c-([0-9]+)/p-([0-9]+)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/catalog/product?catalog=$2&amp;product=$3" ignoreCase="true" xmlns="" />
    <add name="DefaultCategoryRewrite" virtualUrl="(.*)/c-([0-9]+)/c-([0-9]+)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/catalog?catalog=$2&amp;category=$3" ignoreCase="true" xmlns="" />
    <add name="DefaultCatalogRewrite" virtualUrl="(.*)/c-([0-9]+)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/catalog?catalog=$2" ignoreCase="true" xmlns="" />

Like you can see, when system see link like, what matters is c- and p- numbers. All the text is just being ignored. This leads us to the possibility of having a link to same page:! If you understand SEO, right now you are really scared that your e-commerce site can have links like this. Of course in the beginning you will not notice it. Google will not just make up a duplicate link. But sometimes you change your item's display name, even by one character. In dire situations your competitors might make site that will generate wrong links to your pages. This will make search engines think you have different pages. But with same content. And this will do you no good.

There is an easy solution for this.  I have put this code to the top of Product and Catalog master pages:

var product = SiteContext.Current.CatalogContext.CurrentProduct;
var goodUrlForProduct = CatalogLibrary.GetNiceUrlForProduct(product, product.CategoryProductRelations.FirstOrDefault().GetValue(x => x.Category));
if (HttpContext.Current.Request.RawUrl != goodUrlForProduct)
    Response.RedirectPermanent(goodUrlForProduct, true);
var category = SiteContext.Current.CatalogContext.CurrentCategory;
var goodUrlForCategory = CatalogLibrary.GetNiceUrlForCategory(category);
if (HttpContext.Current.Request.RawUrl != goodUrlForCategory)
    Response.RedirectPermanent(goodUrlForCategory, true);

This will effectively check, if URL that is used to request this page, equal to NiceUrl uCommerce would generate for it. If not, tell browser (or a search bot), that there's a permanent 301 redirect to the proper URL.
SEO problem solved!


While I'm at it, it's also a good thing to have all your links either with www. or without it, consistently. By default IIS would serve same page for both URLs:

Of course modern search engines know how to handle such cases, but their SEO advices still contain a note on sticking to same domain name. This one is solved with one line at the top of Config/UrlRewriting.config:

<add name="ForceNoWww" virtualUrl="//www\." redirectMode="Permanent" destinationUrl="//" ignoreCase="true" redirect="Domain" />

I wish you best of luck with your SEO! If it went too well, you might also find Boosting Umbraco with Cache article useful. In any case, the faster your pages are loaded, the better!