I Have some problems with redirecting to another URL based on the query string parameters. I want to redirect users which enter www.domain.com/signup.aspx?p=1 to:
www.domain.com/signup
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx\?p=1" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
Now when they enter www.domain.com/signup.aspx?p=2 they must go to:
www.domain.com/signup/promocode
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx\?p=2" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>
The above rules don't work. What is the right way to do this? Thanks in Advance.
Gr
Martijn
A more robust method of using a value to select a destination is to use Rewrite Maps. The map is essentially a lookup table. This doesn't require a new rule (and an additional evaluation of the URL against a pattern on every request) for every new path.
<rules>
<rule name="Signup Redirect Map" stopProcessing="true">
<match url="^signup\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="p=([^&]+)" />
<add input="{Signups:{C:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:2}" redirectType="Temporary" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="Signups">
<add key="1" value="signup" />
<add key="2" value="signup/promocode" />
<add key="3" value="signup/newcode" />
<add key="n" value="signup/futureproof" />
</rewriteMap>
</rewriteMaps>
Definitions: