Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a site at and I want to configure a set of redirections in IIS7.

To redirect from to I can write:

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

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

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

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

share|improve this question
up vote 2 down vote accepted

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/).

share|improve this answer
thanks for your answer. You mean I should change this in the <condition> block? I thought that changed only when the rule is applied, but had nothing to do with the substitution. – Paolo Tedesco Dec 21 '11 at 7:54
It's indeed the rewritemap block where you specify what should be replaced with what. However, the substitution itself happens in the rule. The rule matches any URL. The condition is just there to be able to call the rewritemap to check if a substitution is available for the given URL. If the rewritemap returns any result (pattern="(.*)"), the condition is true and thus the redirect happens, otherwise not. By not feeding the rewritemap the value of {REQUEST_URI} (which is the full URL) but the value of {REQUEST_FILENAME} it will match substitutions against only the name of the script. – Marco Miltenburg Dec 21 '11 at 18:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.