How to add query string and value using IIS rewrite rule?

I am running IIS 7 with the official rewriting rules module installed. I would like to create a rewrite rule to match this URL:

http://www.sample.com/en-us/test.aspx?q=keyword 

After overwriting the expected result will be:

 http://www.sample.com/en-us/test.aspx?q=keyword&flag=value 

How to create a rule for its implementation?

I checked the following rule, but with no luck, it always got a redirect loop error:

 <rewrite> <rules> <rule name="test" stopProcessing="true"> <match url="(.*)/test\.aspx(.(?!flag=value))*$" /> <action type="Redirect" url="{R:0}&amp;flag=value" appendQueryString="false" logRewrittenUrl="true" /> </rule> </rules> </rewrite> 
+6
source share
1 answer

Found a solution on your own, just share it.

 <rewrite> <rules> <rule name="Redirect for download result page" stopProcessing="true"> <match url="(.*)/test.aspx(.*)" /> <action type="Redirect" url="{R:1}/test.aspx?rf=sp" appendQueryString="true" redirectType="Found" /> <conditions> <add input="{QUERY_STRING}" pattern="flag=value" negate="true" /> </conditions> </rule> </rules> </rewrite> 
+17
source

Source: https://habr.com/ru/post/952013/


All Articles