我有一个 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=something为something清洁的网址。非常简单,而且效果很好。
在 CMS 中很常见,为了防止后端中断,每个子目录都需要<remove name="Clean URLs" />或<clear />在其 web.config 中,因此规则不会被继承。
有没有办法在父规则中指定它根本不应该被子规则继承,方法是将规则的范围限制在当前目录?类似的东西<rule name="Clean URLs" stopProcessing="true" inherit="no">将是史诗般的。