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

Please help me understand rewrite maps, I have this setup:

<rewriteMap name="MyMap">
   <add key="/pages" value="/website/pages/index.aspx" />
   <add key="/pages/page-1" value="/website/pages/page-1/index.aspx" />
   <add key="/pages/page-1/section-1" value="/website/pages/page-1/section-1.aspx" />

Here is my rule:

<rule name="Rewrite rule for MyMap" stopProcessing="true">
   <match url=".*" />
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{MyMap:{REQUEST_URI}}" pattern="(.+)" />
   <action type="Rewrite" url="{C:1}" appendQueryString="true" />

This is working if I try to access these pages:

  • (OK)
  • (OK)
  • (OK)

But I want the possibility to add a query string on any of these pages, example:

  • (FAIL)

When I try to access this page, I get a 404. How can I get this to work?

share|improve this question

migrated from Oct 24 '11 at 18:51

This question came from our site for professional and enthusiast programmers.

By default URL rewrite rules using rewrite maps are created matching on the {REQUEST_URI} variable. This includes the URL + the query string. This allows you to match against URLs with query string parameters and rewrite them to other pages. Very handy but this is apparently not what you want/need.

You want to only match against the URL, without the query string. In order to change this you have to replace {REQUEST_URI} in the condition to {URL}. Then only the URL (without query string) will be matched against the rewrite map. You can then add the query string to the rewritten URL so that the executed script still has access to it.

You end up with a rule like:

<rule name="Rewrite rule for MyMap">
    <match url=".*" />
        <add input="{MyMap:{URL}}" pattern="(.+)" />
    <action type="Rewrite" url="{C:1}" appendQueryString="true" />
share|improve this answer
Great explanation. I'd been wondering how to ignore the QueryString for match purposes, too. – dthrasher Jan 30 '13 at 19:01

Instead of using

<add input="{MyMap:{URL}}" pattern="(.+)" />

you can also try

<add input="{MyMap:{SCRIPT_NAME}}" pattern="(.+)" />

See here:

Can't get static redirects to work with IIS Url Rewrite 2.0

share|improve this answer
Thanks, I will look into this. – Martin Nov 16 '11 at 18:34

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.