简体   繁体   English

IIS7重写规则,对域上的指定页面强制使用小写

[英]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. 我正在尝试创建一个IIS7重写规则,该规则对指定页面强制使用小写字母,以便我可以覆盖指向我的网站的区分大小写的入站链接,以避免Google在/ Contact和/ 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). 使用MatchAny对您的条件进行分组,然后在规则应适用的地方添加所有模式(但请忽略negate属性)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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