IIS7: rewriteMap equivalent of exact match rule

iis-7rewrite

I have a site at mydomain.com/mysite and I want to configure a set of redirections in IIS7.

To redirect from mydomain.com/mysite/old.aspx to mydomain.com/mysite/new.aspx I can write:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
        <match url="old.aspx" />
        <action type="Redirect" url="new.aspx" />
      </rule>
    </rules>

But to get the same with a rewrite map, instead, I also have to specify the /mysite/ part:

<rewriteMaps>
  <rewriteMap name="TestRewriteMap">
    <add key="/mysite/old.aspx" value="/mysite/new.aspx" />
  </rewriteMap>
</rewriteMaps>
<rules>
  <rule name="Redirect rule1 for TestRewriteMap">
    <match url=".*" />
    <conditions>
      <add input="{TestRewriteMap:{REQUEST_URI}}" pattern="(.+)" />
    </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="false" />
  </rule>
</rules>

Is there a way I can avoid specifying the site name in the rewrite map URLs?

Best Answer

I assume your put the web.config with this rewrite rule in the folder /mysite?

You should be able to replace {TestRewriteMap:{REQUEST_URI}} with {TestRewriteMap:{REQUEST_FILENAME}}. Then you you can remove /mysite/ from both the key and value in the <rewriteMap></rewriteMap>. Remember that this will also match any old.aspx deeper in the directory structure (under /mysite/).