我知道这可能是一个简单的问题,但我想从我的 URL 重写规则中排除一个文件。下面是我的web.config文件的重写部分(代码由其他人提供)。我想排除一个名为demo-download的文件.php删除其扩展名。(它导致我使用$ _POST的一些php代码出现问题)。
<rewrite>
<rules>
<rule name="extensionless" stopProcessing="true">
<match url="(.*).php$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*).(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.php" />
</rule>
</rules>
</rewrite>
您可以尝试添加以下行:
<add input="{REQUEST_FILENAME}" pattern=".*demo-download.php" negate="false" />
您必须更改这两个规则。
它将如下所示:
<rewrite>
<rules>
<rule name="extensionless" stopProcessing="true">
<match url="^demo-download" negate="true" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" pattern=".php$" />
</conditions>
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" enabled="true">
<match url="^demo-download.php$" negate="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*).(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.php" />
</rule>
</rules>
</rewrite>
仅当请求的文件名不以 demo-download
开头且扩展名为.php
时,第一条规则才适用。仅当请求的路径不完全demo-download.php
时,第二个才适用