在IIS重写规则中排除路径?

时间:2014-05-09 21:10:32

标签: regex url-rewriting iis-7.5 url-rewrite-module

我有一个将URL转换为小写的重写规则。我想排除一个文件夹,但不知道RegEx。如何从下面的规则中排除“〜/ myfolder”?

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

1 个答案:

答案 0 :(得分:15)

您可以执行以下操作:

    <rules>
        <rule name="LowerCaseRule1" stopProcessing="true">
            <match url="[A-Z]" ignoreCase="false" />
             <conditions>
              <add input="{URL}" negate="true" pattern="^~/myfolder$" />
             </conditions>
            <action type="Redirect" url="{ToLower:{URL}}" />
        </rule>
    </rules>

或...你可以创建另一条规则,对于特定的匹配基本上相反:

    <rules>
        <rule name="LowerCaseRule2" stopProcessing="false">
            <match url="^~/myfolder$" ignoreCase="true" />
            <action type="None" />
        </rule>
    </rules>