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?
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?
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!
See here
You need to specify the url to match, " abc/pqr/xyz", then the query string to match and replace.