我有一个URL重写设置为干净的URL在CMS和我的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>
它基本上将index.php?id=something变成干净的URL的something 。 很简单,它运作良好。
正如在CMS中常见的那样,为了防止后端中断,每个子目录在其web.config中都需要<remove name="Clean URLs" />或<clear /> ,这样规则就不会被inheritance。
有没有一种在父规则中指定它不应该被其子代inheritance的方式,通过某种方式将规则的范围限制在当前目录中? 就像<rule name="Clean URLs" stopProcessing="true" inherit="no">是史诗般的。
4.5小时的Googlesearch后find答案!
http://runtingsproper.blogspot.co.uk/2010/04/solved-breaking-parent-webconfig.html
基本上利用了
<location path="." inheritInChildApplications="false"> <system.webServer> <!-- ... --> </system.webServer> </location>
我最近遇到了类似情况的这个问题。 但是,从rjenkins的答案似乎会导致依赖父设置inheritance的虚拟应用程序的问题。
如果你知道重写规则的名字,你可以这样做:
<rewrite> <rules> <remove name="RewriteNameToDisable" /> </rules> </rewrite>