Enforcing lowercase URLs in Sitecore | Rickard Andersson

Enforcing lowercase URLs in Sitecore

Allowing more than one URL to access the same content on a web site is bad practice. The reason being that search engines tend to dilute the rank of the page if it is accessible via more than one URL. This is common knowledge in the web developer community and often taken into account when designing web sites. It is also quite common to make sure your website generates URLs that only use lowercase letters. In Sitecore, there are various methods (here’s one, and another) that you can implement to support this.

However, often overlooked is the fact that URLs are in fact case sensitive. In the eyes of search engines, /foobar.html is not the same page as /FooBar.html. But most likely, if you pick a page in your Sitecore solution and change the case of some of the letters in the URL, the page still loads. But my web site doesn’t generate any links with uppercase letters, you say? True, but what if some high profile web site links to your site and they type in the URL manually using uppercase letters?

The solution to the problem is to detect if the URL contains any uppercase letters and if so, issue a 301 permanent redirect to the lowercase version of the same URL. That way, search engines, even though they were fed a mixed or uppercase version of the URL, will follow the redirect to the correct lowercase version of the URL.

You could implement this functionality in Sitecore using a LinkProvider, but in my opinion, the most elegant solution is to not involve Sitecore at all and instead use Microsoft’s URL Rewrite for IIS. The Rewrite Module supports pretty much all of the features of Apache’s mod_rewrite and even has import support for .htaccess style rules. For enforcing lowercase URLs, it has built-in standard rules that you can use. After you’ve installed the module, navigate to the site in question in IIS Manager, go to the URL Rewrite module and add a new rule. Under the SEO heading, you’ll find “Enforce lowercase URLs”. Apply the rule, and voila!

URL Rewrite Module

It should be noted that I have only tried this on content delivery servers, but I don’t think the Sitecore back-end will have any problems with this.

Update: Turns out that some features of page editor don’t work properly if you enable this on content management servers. In other words, don’t. Just use it on the front-end servers. Also, I forgot to mention this in the post, but when you apply a rule via IIS Manager, the rule is actually stored in your web.config, so be careful not to overwrite the file or your rules will disappear.

Post a Comment

Comments are moderated. Your email is never published nor shared.