IIS Redirect With a Querystring/URL Vars

Basics about HTTP Redirect

IIS has lots of built in utilities and GUI tools for managing websites. If you need to do a redirect from one URL to another, it couldn’t be easier, especially if you need to include the querystring or URL vars (variables).

By the way, if you just need a simple way to redirect your domain.com to www.domain.com, then read this article.

Setting up HTTP Redirect

It is dead easy. Open IIS Manager and click on your website. In the right panel you will see HTTP Redirect.

If you don’t have it you will need to install it. See how to install HTTP Redirect. Double click on it.

iis-http-redirect-1

In this example, we want to redirect everything that lands on processio.com (host names don’t matter – everything will be redirected) to http://www.domain.com/. Make sure to check “Redirect requests to this this destination:” and “Redirect all requests to exact destination (instead of relative destination). Unless you have a different reason to do so, use 301 as the redirect, and then click Apply.

Note that I have included $V$Q at the end, which will ensure that any querystrings will be added to the end of the redirect URL.

Note: $V$Q used to be $S$Q in IIS 6. IIS 7 and up uses $V$Q.

iis-http-redirect-2

Since this GUI tool creates the related web.config file, let’s take a look:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <httpRedirect enabled="true" destination="http://www.domain.com$V$Q" exactDestination="true" httpResponseStatus="Permanent" />
 </system.webServer>
</configuration>

That’s it, you’re done!

 

 

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.