Iis web.config将数字id重写为查询字符串时出现问题

Iis web.config将数字id重写为查询字符串时出现问题,iis,web-config,rewrite,Iis,Web Config,Rewrite,我希望在我的web.config中有一个重写规则,该规则将转换以下URL: mypage to mypage.php mydirectory/mypage to mydirectory/mypage.php mydir2/mydir1/mypage to mydir2/mydir1/mypage.php mypage/12345 to mypage.php?id=12345 mydirectory/mypage/12345 to mydirectory/mypage.php?id=12345 m

我希望在我的
web.config
中有一个重写规则,该规则将转换以下URL:

mypage to mypage.php
mydirectory/mypage to mydirectory/mypage.php
mydir2/mydir1/mypage to mydir2/mydir1/mypage.php
mypage/12345 to mypage.php?id=12345
mydirectory/mypage/12345 to mydirectory/mypage.php?id=12345
mydir2/mydir1/mypage/12345 to mydir2/mydir1/mypage.php?id=12345
作为Apache中的
.htaccess
文件,我只需使用

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^(.*)\/([0-9]+)$ $1.php?id=$2&%1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^(.*)$ $1.php?%1 [L]
我尝试用
web.config
在IIS中复制这种行为。以下是我目前掌握的情况:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
<rewrite>
  <rules>
    <rule name="hide .php extension without losing ?id=" stopProcessing="true">
      <match url="^(.*)/([0-9]+)$" ignoreCase="true" />
      <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
      </conditions>
      <action type="Rewrite" url="{R:0}.php?id={R:2}" />
    </rule>
    <rule name="hide .php extension" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="true" />
      <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
      </conditions>
      <action type="Rewrite" url="{R:0}.php" />
    </rule>
  </rules>
</rewrite>
</system.webServer>
</configuration>

但当我进入浏览器并键入
http://localhost/mydirectory/mypage/12345
,我找不到404页。我在404页面上看到请求url是
http://localhost:80/mydirectory/mypage/12345
物理路径是
C:\inetpub\wwwroot\mydirectory\mypage\12345


我做错了什么?

哦,等等,我知道了。我将节点
name=“hide.php扩展名替换为

<rule name="hide .php extension without losing ?id=" stopProcessing="true">
  <match url="^(.*)/([0-9]+)$" ignoreCase="true" />
  <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="{R:1}.php?id={R:2}" />
</rule>