简体   繁体   中英

IIS7 rewrite rule that forces lower case for specified pages on domain

I am trying to create a IIS7 rewrite rule that forces lower case for specified pages so that I can override case sensitive inbound links to my site to avoid Google duplicate content on urls like /Contact and /contact. I have found a rule that works well except it includes all pages on the domain and then you can specify pages to exclude.

<rule name="Lower Case Rewrite" enabled="true" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="/ordering/shoppingcart/" negate="true" />
</conditions>
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

Would it be possible to invert the rule so that it does not apply the to lower case except on the pages I specify in the rule. The reason for me wanting to do it like this is the admin, cart and other sections of the site are failing when the rule is implemented and the site is too big to check all the pages and handler calls.

Any help would be great!

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

Like this:

<rule name="Lower Case Rewrite" enabled="true" stopProcessing="true">
  <match url=".*[A-Z].*" ignoreCase="false" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{URL}" pattern="/content/" />
    <add input="{URL}" pattern="/content2/" />
  </conditions>
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

Group your conditions with MatchAny, then add all patterns where the rule should apply (but leave out the negate attribute).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM