简体   繁体   中英

Convert URL to lower case only for ASPX and extension less URLs

I am using this rule in 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>

How do I modify it so that it only redirects the urls that the user is likely to see in the browser like /MyPage.aspx and /MyPage and perhaps /MyPage.htmL

EDIT: I ended up using this: (this solves problem with DotNetNuke and reduces unnecessary redirects)

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

For Extensionless and ASPX only to lowercase:

<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$ matches file names that end with .aspx ( $ is end of line)

\\. matches anything with a dot in the file name (that wasn't already matched) and negates it from the match

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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