【发布时间】:2014-02-28 09:42:06
【问题描述】:
我正在尝试创建一个重写规则,它将所有 .html 页面重定向到一个 URL,不包括单个文件夹(和所有子文件夹)。我做了很多谷歌搜索,并试图从类似的情况中拼凑出一些东西。
原始的重写规则可用于重定向所有 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>
然后我添加了一个单独的规则,希望第一个规则会停止处理并且重定向不会发生
<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>
这继续将所有 html 文件重定向到 www.example.com。
然后我继续尝试使用条件来排除某些目录,如下所示
<rewrite>
<rules>
<rule name="redirect legacy html" enabled="true" stopProcessing="true">
<match url="(.+).html$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_URI}" pattern="/(scripts|admn)/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.example.com" />
</rule>
</rules>
</rewrite>
但这也不起作用 - 重定向仍然发生
我一直在尽可能地使用 RegExr 来测试我的各种正则表达式,但我运气不佳。不知道是RegEx问题还是重写问题。
谁能帮忙?
【问题讨论】:
标签: regex web-config url-rewrite-module