Guy MacArthur Team : Web Development Tags : Web Development SEO Umbraco

IIS URL redirects to lowercase and Umbraco CMS

Guy MacArthur Team : Web Development Tags : Web Development SEO Umbraco

URL case sensitivity is usually the last thing a web developer thinks about when building a site, however, it’s usually pretty important to the likes of Google and the others. This is because, though a webserver will generally ignore casing on a URL, and so serve up the same page for /my-awesome-page.html and /My-Awesome-Page.html, most of search engines and analytics services will see them as different pages. So, to make them SEO friendly, we generally enforce lowercase URL redirects.

It’s simple with IIS URL Rewrite

If you don’t already have IIS URL Rewrite installed for IIS, you can find it using Web Platform Installer or just grab it from the download page here, IIS URL Rewrite downloads.

Now, in your web.config of your website, add the following to the web server section:

<system.webServer> 
...
  <rewrite>
<rules>
<!-- Redirect rule to force all URLs to lowercase -->
<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
</rules>
</rewrite>

...
</system.webServer>

Now, all of your URLs will automatically permanently redirect to the lowercase equivalent.

Umbraco CMS managed site? Just one last thing …

If you’re using Umbraco to manage your website, some of the internal workings of the CMS will start failing. This is because a few service calls and inner workings are actually case sensitive, however, this is easily fixed with a small addition to the rule shown above. You just need to add two exclusions to the rule.

<system.webServer> 
...
  <rewrite>
<rules>
<!-- Redirect rule to force all URLs to lowercase -->
<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
<conditions>
<add input="{REQUEST_URI}" pattern="^.*/umbraco" negate="true" />
<add input="{REQUEST_URI}" pattern="^.*/install" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>

...
</system.webServer>

With those two exclusions, the CMS is able to work as normal, and your site user facing URLs are still redirected to lowercase as expected.

One slight thing to note is that this works for sites with the umbracoPath setting still set to its default value of ~/umbraco. If you change that, you may need to add one more condition in the set above.

Good luck, and happy coding.