Asp.net

IIS URL 重寫:添加尾部斜杠,.html 和 .aspx 除外

  • October 4, 2012

通過 IIS URL 重寫模組向所有 URL 添加尾部斜杠已廣泛傳播,但是如何為以 .html 和 .aspx 結尾的 URL 添加例外

今天我有這個:

<rule name="Add trailing slash" stopProcessing="true">
 <match url="(.*[^/])$" />
 <conditions>
   <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
   <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
   <!-- Doesn't seem to be working -->
   <!--<add input="{REQUEST_URI}" pattern="(.*?).html$" negate="true" />-->
   <!--<add input="{REQUEST_URI}" pattern="(.*?).aspx$" negate="true" />-->
 </conditions>
 <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>

如果你想把事情做好,你必須自己做,很明顯……

這是我的問題的解決方案:

<rule name="Add trailing slash" stopProcessing="true">
 <match url="(.*[^/])$" />
 <conditions>
   <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
   <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
   <add input="{REQUEST_FILENAME}" pattern="(.*?)\.html$" negate="true" />
   <add input="{REQUEST_FILENAME}" pattern="(.*?)\.aspx$" negate="true" />
 </conditions>
 <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>

更新我在部落格上對此進行了更詳細的介紹

引用自:https://stackoverflow.com/questions/12724455