仅针对ASPX和扩展名较少的URL将URL转换为小写

时间:2013-09-18 10:59:19

标签: asp.net regex url-rewriting iis-7.5

我在IIS 7中使用此规则

<rule name="Convert to lower case" enabled="true" stopProcessing="true">
  <match url=".*[A-Z].*" ignoreCase="false" />
  <conditions>
    <add input="{URL}" pattern="(.*)/admin/*" negate="true" />
  </conditions>
  <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

如何修改它以便它只重定向用户可能在浏览器中看到的网址,如/MyPage.aspx和/ MyPage以及/MyPage.htmL

编辑:我最终使用了这个:(这解决了DotNetNuke的问题,并减少了不必要的重定向)

    <rule name="Convert to lower case" enabled="true" stopProcessing="true">
      <match url=".*[A-Z].*" ignoreCase="false" />
      <conditions>
        <add input="{URL}" pattern="(.*)/(admin|desktopmodules|host|tabid)/*" negate="true" />
        <add input="{URL}" pattern="^.*\.(xml|ashx|axd|css|js|jpg|jpeg|png|gif)$" negate="true" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
    </rule>

1 个答案:

答案 0 :(得分:1)

对于Extensionless和ASPX,仅限小写:

<rule name="LowerCaseRule" stopProcessing="true">
  <match url="[A-Z]" ignoreCase="false" />
  <action type="Redirect" url="{ToLower:{URL}}" />
  <conditions logicalGrouping="MatchAny">
    <add input="{REQUEST_FILENAME}" pattern="\.aspx$" />
    <add input="{REQUEST_FILENAME}" pattern="\." negate="true" />
  </conditions>
</rule>

\.aspx$匹配以.aspx结尾的文件名($为行尾)

\.匹配文件名中带点的任何内容(尚未匹配)并从匹配中取消