Mod rewrite IIS重写规则如何检查requesturl+。php文件是否存在于规则中

Mod rewrite IIS重写规则如何检查requesturl+。php文件是否存在于规则中,mod-rewrite,iis-7,url-rewriting,Mod Rewrite,Iis 7,Url Rewriting,我想检查requestedurl+.php文件是否存在 在apache中,我可以使用RewriteCond%{REQUEST_FILENAME}.php-f来实现这一点 这样它就可以将我的请求test.com/login重写为test.com/login.php 我想对iis重写规则执行同样的操作 我已经试过了 <rewrite> <rules> <rule name="Imported Rule 1" stopProcessing="true">

我想检查requestedurl+.php文件是否存在

在apache中,我可以使用RewriteCond%{REQUEST_FILENAME}.php-f来实现这一点

这样它就可以将我的请求test.com/login重写为test.com/login.php

我想对iis重写规则执行同样的操作

我已经试过了

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}\.php" matchType="IsFile" />
      </conditions>
      <action type="Rewrite" url="{R:1}.php" />
    </rule>
    <rule name="Imported Rule 2">
      <match url="^(.*)$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="allpages.php" />
    </rule>
  </rules>
</rewrite>

但它不起作用


提前感谢您的帮助

在第一条规则中将
{REQUEST\u FILENAME}\.php
更改为
{REQUEST\u FILENAME}.php

此外,不需要检查请求的URL是否作为目录存在

要仅在login.php退出时将“test.com/login”重写为“test.com/login.php”,请使用:

<rule name="Rewrite to PHP">
  <match url="^(.*)$" />
  <conditions>
    <add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
  </conditions>
  <action type="Rewrite" url="{R:0}.php" />
</rule>

测试