How to redirect a url only with specific parameters in IIS

I have a url that looks like this:

www.mywebsite.com/page.aspx?code=1.a

I want to redirect this URL via IIS to:

www.mywebsite.com/page.aspx?code=1.b

I would like to do this through IIS and not within the code.

I have various other website urls that look like:

www.mywebsite.com/page.aspx?code=2
www.mywebsite.com/page.aspx?code=3.a
www.mywebsite.com/page.aspx?code=6.c

I don’t want these to be affected.

Thanks.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

An easy way to do this in IIS 7.5 is to install the URL Rewrite extension from Microsoft into IIS.

http://www.iis.net/downloads/microsoft/url-rewrite

Once you have it installed, you can just add a rule to redirect from ?code=1.a to ?code=1.b. In IIS, you’ll see a new entry called URL Rewrite under the IIS heading for your website. You can use the editor there to create a new rule. Once the rule is created, it will be written into your web.config file.

In the web.config file, the rule should look something like this:

<system.webServer>
    ...
    <rewrite>
        <rules>
            <rule name="Code=1.a redirect" patternSyntax="ExactMatch" 
                  stopProcessing="true">
                <match url="page.aspx" />
                <action type="Redirect" url="page.aspx?code=1.b"
                        appendQueryString="false" redirectType="Permanent" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="code=1.a" />
                </conditions>
            </rule>
        </rules>
    </rewrite>
    ...
</system.webServer>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x