【问题标题】:IIS7 rewrite rule that forces lower case for specified pages on domainIIS7 重写规则,强制域上指定页面的小写
【发布时间】:2013-01-11 23:15:37
【问题描述】:

我正在尝试创建一个 IIS7 重写规则,该规则强制指定页面小写,以便我可以覆盖到我的网站的区分大小写的入站链接,以避免 Google 在 /Contact 和 /contact 等 URL 上重复内容。 我找到了一个很好的规则,除了它包含域上的所有页面,然后您可以指定要排除的页面。

<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>

是否可以反转规则,使其不应用于小写,除了我在规则中指定的页面。 我想要这样做的原因是当规则实施时网站的管理员、购物车和其他部分都失败了,并且网站太大而无法检查所有页面和处理程序调用。

任何帮助都会很棒!

【问题讨论】:

  • 你检查过 IIS 中 URL Rewrite 的 GUI。它非常直观,也许您可​​以更轻松地解决您的问题..

标签: asp.net iis-7 web-config


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

【讨论】:

    【解决方案2】:

    像这样:

    <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>
    

    使用 MatchAny 对您的条件进行分组,然后添加规则应适用的所有模式(但省略 negate 属性)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 2012-08-12
      • 1970-01-01
      • 2011-02-16
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多