Search code examples
http-redirectiisiis-7iis-expressurl-rewrite-module

IIS URL Rewrite Module - Change Querystring Parameter Value forming multiple query string


   <rule name="replace query string" enabled="true" stopProcessing="true">
                    <match url="(.*)(ip=1)(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{QUERY_STRING}" pattern="(.*)(ip=1)(.*)" />
                    </conditions>
                    <action type="Redirect" url="{R:0}?{C:0}ip=0{C:2}" appendQueryString="false" logRewrittenUrl="true" />
                </rule>

I have used the above rule and its creating duplicate query string

I have used below url

http://test.com/track/?ip=1&_=1589821794782

My main goal is to update the test.com to api.com and then change ip=1 to ip=0.

Can you please help me I'm new to this?

Generated URL http://test.com/track/?ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=0&=1589821794782&ip=1&=1589821794782

enter image description here


Solution

  • there is some issue in your rule pattern. you can see the below failed request tracing result of your rule:

    enter image description here

    to fulfill your retirement you could try to use below rule:

    <rule name="replace query string" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="test.com" />
                        <add input="{QUERY_STRING}" pattern="ip=1(.*)" />
                    </conditions>
                    <action type="Redirect" url="http://api.com/{R:1}?ip=0{C:1}" appendQueryString="false" logRewrittenUrl="true" />
                </rule>