IIS URL rewrite module url's to lowercase

Tippu picture Tippu · Aug 14, 2013 · Viewed 15.1k times · Source

For better SEO we are using URL rewrite to convert all the URL's to lowercase. I set this one as mentioned in this the below article.

Everything is working fine from URL perspective, but we see lot of 301 redirects when we check in fiddler. It looks like the images, javascript, css, jquery ajax calls and everything is getting converted into lower case. I am trying to remove that and want to rewrite only aspx extension and no extension urls. I tried to play around the matchurl without any success. Any help or guidelines will be highly appricated.

Thanks

Edit: My Current rule is

 <rules>

    <rulename="LowerCaseRule1"patternSyntax="ExactMatch"stopProcessing="true">
      <matchurl="[A-Z]"ignoreCase="false"/>
      <actiontype="Redirect"url="{ToLower:{URL}}"/>
    </rule>
  </rules>

Answer

cheesemacfly picture cheesemacfly · Aug 15, 2013

You could probably use something as follow:

<rule name="LowerCaseRule1" stopProcessing="true">
    <match url="[A-Z]" ignoreCase="false" />
    <action type="Redirect" url="{ToLower:{URL}}" />
    <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_FILENAME}" pattern="\.aspx$" />
        <add input="{REQUEST_FILENAME}" pattern="\." negate="true" />
    </conditions>
</rule>

The rule will be triggered only if one of the condition is true:

  • The first one checks if the requested path (filename) ends with .aspx.
  • The second one checks if the if the requested path (filename) doesn't contain a . (so doesn't have an extension)