3

I have a URL in the format

abc/pqr/xyz/?word1

and this needs to redirect to

abc/pqr/xyz/?word2

Is is possible to do using IIS7 rewrite?

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
  • You want to rewrite the query string?? – cheesemacfly Mar 13 '13 at 18:45
  • @cheesemacfly Yes, a category of information on our site has been changed, so this whole querystring needs to be redirected for anyone who's bookmarked old links. Obviously, we're fixing any links in our site already, the redirect is just so that old links don't break :) – Owen Blacker Mar 14 '13 at 11:39

2 Answers2

3

It is possible using the IIS7 rewrite module with the following rule:

<rule name="Rewrite querystring" stopProcessing="true">
    <match url="^abc/pqr/xyz/?$" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="^word1$" />
    </conditions>
    <action type="Redirect" url="{R:0}?word2" appendQueryString="false" />
</rule>

What it does is: check that the url is abc/pqr/xyz/ or abc/pqr/xyz and the query string exactly word1. If yes, it redirects the user to the same url ({R:0}) but appending ?word2 instead.

It is important to have the appendQueryString="false" option as you don't want the module to append your word1 at the end.

By default, if not specified, the redirect is a 301 (permanent), that, regarding @Owen comment, seems to be the best fit for your case!

cheesemacfly
  • 11,622
  • 11
  • 53
  • 72
0

See here

You need to specify the url to match, " abc/pqr/xyz", then the query string to match and replace.

Community
  • 1
  • 1
rbedger
  • 1,177
  • 9
  • 20