title: IIS7 URL Redirect with Regex
body: <p>I'm preparing for a major overhaul of our shopping cart, which is going to completely change how the urls are structured. For what its worth, this is for Magento 1.7.</p>
  
  <p>An example URL would be:
  <code>{domain}/item/sub-domain/sub-sub-domain-5-16-7-16-/8083770?plpver=98&amp;categid=1027&amp;prodid=8090&amp;origin=keyword</code></p>
  
  <p>and redirect it to <code>{domain}/catalogsearch/result/?q=8083710</code></p>
  
  <p>My web.config is:</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="Magento Required" stopProcessing="false"&gt;
        &lt;match url=".*" ignoreCase="false" /&gt;        &lt;conditions&gt;
                          &lt;add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" /&gt;
                          &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt;
                          &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;
      &lt;/conditions&gt; &lt;action type="Rewrite" url="index.php" /&gt;
      &lt;/rule&gt;
                  &lt;rule name="Item Redirect" stopProcessing="true"&gt;
                      &lt;match url="^item/([_\-a-zA-Z0-9]+)/([_\-a-zA-Z0-9]+)/([_\-a-zA-Z0-9]+)(\?.*)" /&gt;
                      &lt;action type="Redirect" url="catalogsearch/result/?q={R:3}" appendQueryString="true" redirectType="Permanent" /&gt;
                      &lt;conditions trackAllCaptures="true"&gt;
                      &lt;/conditions&gt;
                  &lt;/rule&gt;
     &lt;/rules&gt;
     &lt;/rewrite&gt;
          &lt;httpProtocol allowKeepAlive="false" /&gt;
          &lt;caching enabled="false" /&gt;
          &lt;urlCompression doDynamicCompression="true" /&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Right now it seems the redirect is completely ignored, even though in the IIS GUI the sample url passes the regex test. Is there a better way to redirect or is there something wrong with my web.config?</p>