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:

      <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?


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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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