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:
<rewrite>
<rules>
<rule name="Old Site to New" patternSyntax="Wildcard" stopProcessing="true">
<match url="*OldPage.aspx*" />
<action type="Rewrite" url="NewPage.aspx" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
I am using wildcards, but a suggestion with either regex or wildcards would be OK by me.
This should do the job based on your URL examples:
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.