web.config trouble with rewriting the numeric id as a query_string
<p>I want a rewrite rule in my <code>web.config</code> that will translate the following urls:</p>

<pre><code>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
</code></pre>

<p>As a <code>.htaccess</code> file in Apache, I simply do this with </p>

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^(.*)$ $1.php?%1 [L]
</code></pre>

<p>I tried reproducing this behaviour in IIS with a <code>web.config</code>. Here's what I have so far:</p>

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

<p>But when I go to my browser and type <code>http://localhost/mydirectory/mypage/12345</code>, I get a 404 page not found.  I see on the 404 page that request url is <code>http://localhost:80/mydirectory/mypage/12345</code> and physical path is <code>C:\inetpub\wwwroot\mydirectory\mypage\12345</code>.  </p>

<p>What am I doing wrong?</p>