Redirect and force URLs to lowercase and remove .aspx from filenames

For my day job I have a nice mix between PHP, WordPress and ASP .NET 4.0 coding with various projects. I’ve had to make some of our e-commerce projects more SEO friendly as I found out that people were sharing the same pages from our website with a mixture of upper-case urls and lower-case urls. Whilst I was at if I thought I would go a little step further and remove the default .aspx on the end to make them look nicer to the eye.

Also with ASP, webpages are treated slightly different than on Apache/Linux servers with PHP. About-us.aspx is different to about-us.aspx and we have to make sure there is a redirect or/and a canonical tag in place to let search engines know they are the same page. For time being I’m only going to show you to¬†redirect and force urls to lowercase rule. I’ve set this using the IIS 7.0 URL Rewrite tool and here is the output code:

Make sure the following rules are within the web.config file and between ‘<system.webServer>’ tag.

Redirect and force URls to lowercase using IIS, Web.config and the URL Rewrite function

      <rule name="LowerCaseRule1" stopProcessing="true">
         <match url="[A-Z]" ignoreCase="false" />
         <action type="Redirect" url="{ToLower:{URL}}" />

Now that we have the ‘camel case’ / uppercase urls redirecting to their lower-case counterparts we can move on to making the URLs of your website look pretty. We do this as it’s more user-friendly to the eye and Google (our friends) like this as your webpages will be easier to remember from a customer/visitor’s point of view.
The following code goes in the same place as a new rule within the <rules> tag. Just append the one above for lower-case URLs.

Remove .aspx from pages using URL Rewrite module in IIS for

This will redirect aspx pages to the pretty looking url (without the .aspx):

<rule name="Redirect to clean URL" stopProcessing="true">
   <match url="^([a-z0-9/]+).aspx$" ignoreCase="true"/>
   <action type="Redirect" url="{R:1}"/>

Where you seel url=”{R:1}” you may want to replace this with url=”{ToLower:{R:1}}” so your urls follow suit with your first rule for lower case filenames.

There you have it, the ability to have pretty looking urls and forcing your project to use one url instead of a mix between uppercase and lowercase filenames.

All these rules can be achieved from using the URL Rewrite tool for IIS mentioned above, make sure this is installed to achieve the result and do even more like making query strings better looking and user-friendly.