小编Sna*_*lac的帖子

web.config重写以重定向html文件但排除某些文件夹

我正在尝试创建一个重写规则,将所有.html页面重定向到单个URL,不包括单个文件夹(以及所有子文件夹).我做了很多googleing并试图从类似的情况一起拼凑一些东西.

原始重写规则用于重定向所有html文件,但我试图在存在文件夹匹配时放入一个先前的规则来停止处理.

我从这开始就有用了

<rewrite>
  <rules>
    <rule name="redirect legacy html" enabled="true" stopProcessing="true">
      <match url="(.+).html$" ignoreCase="true" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="^$" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com" />
    </rule>
  </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

然后我添加了一个单独的规则,希望第一个停止处理,重定向不会发生

<rewrite>
  <rules>
    <rule name="ignore redirects in admin" enabled="true" stopProcessing="true">
      <match url="/script|admn/(.+).html$" ignoreCase="true" />
      <action type="None" />
    </rule>
    <rule name="redirect legacy html" enabled="true" stopProcessing="true">
      <match url="(.+).html$" ignoreCase="true" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="^$" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com" />
    </rule>
  </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

这继续将所有html文件重定向到www.example.com.

然后我继续尝试使用条件来排除某些目录,如下所示

<rewrite>
  <rules>
    <rule name="redirect legacy …
Run Code Online (Sandbox Code Playgroud)

regex web-config url-rewrite-module

7
推荐指数
1
解决办法
6431
查看次数

标签 统计

regex ×1

url-rewrite-module ×1

web-config ×1