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
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Stumpy7
  • 252
  • 3
  • 14
  • http://serverfault.com/questions/372991/iis-url-rewrite-module-query-string-parameters – bdoshi Apr 01 '14 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. – Stumpy7 Apr 02 '14 at 09:14

1 Answers1

3

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>
bdoshi
  • 1,051
  • 12
  • 19
  • 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. – David Kolar Nov 07 '14 at 22:03