小编Ric*_*nks的帖子

防止URL重写规则被IIS7中的子目录继承

我有一个 CMS 中干净 URL 的 URL 重写设置,我的 web.config 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Clean URLs" stopProcessing="true">
                    <match url="^([^/]+)/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="?id={R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

它基本上变成index.php?id=somethingsomething清洁的网址。非常简单,而且效果很好。

在 CMS 中很常见,为了防止后端中断,每个子目录都需要<remove name="Clean URLs" /><clear />在其 web.config 中,因此规则不会被继承。

有没有办法在父规则中指定它根本不应该被子规则继承,方法是将规则的范围限制在当前目录?类似的东西<rule name="Clean URLs" stopProcessing="true" inherit="no">将是史诗般的。

iis rewrite iis-7 url web.config

16
推荐指数
2
解决办法
1万
查看次数

标签 统计

iis ×1

iis-7 ×1

rewrite ×1

url ×1

web.config ×1