2

How can I modify just the value of a specific QueryString parameter if it is equal to a specified value, using a rewrite rule? I only want to change this value, and do not want to affect the rest of the url or any other query string parameters.

eg. If query string parameter ID = '123' then I want to rewrite the value as 'abc'

And this should work regardless of the form of the URL:

http://mysite/page.aspx?ID=**123** should resolve to  http://mysite/page.aspx?ID=**abc**

http://mysite/?ID=**123** should resolve to  http://mysite/?ID=**abc**

http://mysite/page.aspx?name=bob&ID=**123** should resolve to  http://mysite/page.aspx?name=bob&ID=**abc**

http://mysite/page.aspx?name=bob&ID=**123**&age=33 should resolve to  http://mysite/page.aspx?name=bob&ID=**abc**&age=33
2
  • serverfault.com/questions/372991/… Commented Apr 1, 2014 at 14:05
  • not the same. I want to be able to change the value of ID to abc only if it is equal to 123 and I want to leave the rest of the URL as is. Commented Apr 2, 2014 at 9:14

1 Answer 1

4

This rule will work for you.

<rule name="replace query string" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
      <add input="{QUERY_STRING}" pattern="(.*)(id=123)(.*)" />
    </conditions>
    <action type="Redirect" url="{R:0}?{C:1}id=abc{C:3}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
Sign up to request clarification or add additional context in comments.

1 Comment

Don't know if this helped @Stumpy7, but I had the same problem and this totally helped me. Thank you! I hope this gets marked as the accepted answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.