加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – IIS URL Rewrite:添加除.html和.aspx之外的尾部斜杠

发布时间:2020-12-15 23:11:46 所属栏目:asp.Net 来源:网络整理
导读:通过IIS URL Rewrite Module向所有URL添加尾部斜杠广泛传播,但如何为以.html和.aspx结尾的URL添加异常? 今天我有这个: rule name="Add trailing slash" stopProcessing="true" match url="(.*[^/])$" / conditions add input="{REQUEST_FILENAME}" matchTy
通过IIS URL Rewrite Module向所有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>

更新:I blogged about this in more detail.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读