Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 need to create a rewrite rule as follows:

OldPage.aspx?UserId=12345 should redirect to NewPage.aspx?Id=12345

the '12345' can be any numeric value.)

I have the page redirect working, but not sure how to change the 'UserId' to 'Id' (I can do it in my code, but would rather do it in the web.config).

This is what I have:

            <rule name="Old Site to New" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*OldPage.aspx*" />
                <action type="Rewrite" url="NewPage.aspx" appendQueryString="true" logRewrittenUrl="true" />

I am using wildcards, but a suggestion with either regex or wildcards would be OK by me.

share|improve this question
up vote 2 down vote accepted

This should do the job based on your URL examples:

<rule name="Old2New">
    <match url="^OldPage\.aspx$" />
        <add input="{QUERY_STRING}" pattern="UserId=(\d+)" />
    <action type="Rewrite" url="NewPage.aspx?Id={C:1}" appendQueryString="false" />

The common mistake that a lot of people do is trying to match whole URL including query string. The reality is: when matching URL, the pattern get applied to path part of it and query string has to be matched separately.

share|improve this answer
Works perfectly...sometimes you just need a working example to see the light...and you are right, I was trying to match the whole URL – EJB Aug 9 '11 at 23:51

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.