3

我的 web.config 中有以下重写规则。规范规则有效,但小写规则无效。

我正在尝试像这样测试它:www.mysite.com/UPPERCASE。我本来希望 url 被转换为 www.mysite.com/uppercase,但它仍然是大写的。我究竟做错了什么?

<rewrite xdt:Transform="Insert">
  <rules>
    <rule name="LowerCaseRule" patternSyntax="ExactMatch">
      <match url="[A-Z]" ignoreCase="false"/>
      <action type="Redirect" url="{ToLower:{URL}}"/>
    </rule>
    <rule name="CanonicalHostName">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www.mysite.com$" negate="true" />
      </conditions>
      <action type="Redirect" url="{MapSSL:{HTTPS}}www.mysite.com/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
  <rewriteMaps>
    <rewriteMap name="MapSSL" defaultValue="OFF">
      <add key="ON" value="https://" />
      <add key="OFF" value="http://" />
    </rewriteMap>
  </rewriteMaps>
</rewrite>
4

3 回答 3

4

您应该patternSyntax="ExactMatch"从规则中删除,LowerCaseRule因为在您的情况下,您希望使用正则表达式系统(默认情况下或通过设置提供patternSyntax="ECMAScript")。

所以你的规则应该是:

<rule name="LowerCaseRule">
  <match url="[A-Z]" ignoreCase="false"/>
  <action type="Redirect" url="{ToLower:{URL}}"/>
</rule>
于 2013-09-12T20:37:19.483 回答
0

尝试这个

<rule name="LowerCaseRule" stopProcessing="true">
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{URL}" pattern=".*[A-Z].*" ignoreCase="false" />
        </conditions>
        <action type="Redirect" url="{ToLower:{URL}}" />
    </rule>
于 2014-01-31T12:52:39.650 回答
0

这对我来说更好。我注意到{URL}当您有类似的路径时无法正确解析cassete.axd/scripts/myscript.js?xxx,它将重定向到cassette.axd?xxx

    <rule name="LowerCaseRule - HTTPS">
      <match url="[A-Z]" ignoreCase="false"/>
      <conditions>
        <add input="{HTTPS}" pattern="on" ignoreCase="true"/>
      </conditions>
      <action type="Redirect" url="https://{ToLower:{HTTP_HOST}}{ToLower:{PATH_INFO}}" appendQueryString="true"/>
    </rule>

    <rule name="LowerCaseRule - HTTP">
      <match url="[A-Z]" ignoreCase="false"/>
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
      </conditions>
      <action type="Redirect" url="http://{ToLower:{HTTP_HOST}}{ToLower:{PATH_INFO}}" appendQueryString="true"/>
    </rule>

希望这可以帮助某人。

于 2015-12-04T03:07:54.117 回答