I have added multiple http bindings to my site like:
http://sub1.domain.com
http://sub2.domain.com
http://sub3.domain.com
http://sub4.domain.com
http://sub5.domain.com
I need to add different query string to those URLs when user hits any of those URLs.
http://sub1.domain.com/?qs=10
http://sub2.domain.com/?qs=15
http://sub3.domain.com/?qs=25
http://sub4.domain.com/?qs=30
http://sub5.domain.com/?qs=50
I'm thinking to keep query string values in appSettings keys. like
<appSettings>
<add key ="sub1" value="10" />
<add key ="sub2" value="15" />
...
</appSettings>
I wrote following rule that appends fixed query string. But it'll append qs=10 for all five URLs. But I'm clueless about making it dynamic.
<rule name="Add query string param" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="qs=10" negate="true" />
<add input="&{QUERY_STRING}" pattern="^(&.+)|^&$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}?qs=10{C:1}" appendQueryString="false" />
</rule>
You should probably look at rewrite maps. I haven't tested it, but it should be something like this:
<rewrite>
<rewriteMaps>
<rewriteMap name="SubDomainQueryStrings">
<add key="sub1.domain.com" value="qs=10" />
<add key="sub2.domain.com" value="qs=15" />
<add key="sub3.domain.com" value="qs=25" />
<add key="sub4.domain.com" value="qs=30" />
<add key="sub5.domain.com" value="qs=50" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Add query string param" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="{SubDomainQueryStrings:{HTTP_HOST}}" negate="true" />
<add input="&{QUERY_STRING}" pattern="^(&.+)|^&$" />
</conditions>
<action type="Redirect" url="{R:0}?{SubDomainQueryStrings:{HTTP_HOST}}{C:1}" appendQueryString="false"/>
</rule>
</rules>
<rewrite>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With