Permanent 301 Redirect with QueryString in IIS

If anyone's ever tried to move domain, you'll know its a pain. One way to make things a little easier is to provide an automatic 301 redirect from your old domain to your new one - this marks the new destination as a permanent change, and will generally be picked up by search engines.

IIS provides an easy way to do this - but it's not immediately obvious how to get it to forward querystrings too - for instance, if you wanted to forward developerfusion.com/show.aspx?id=20 to developerfusion.co.uk/show.aspx?id=20. Here's now! (This works in both IIS 5 and IIS 6)

  1. Go into the IIS site properties for the domain you're moving from. In the "Home Directory" tab, click the option "A redirection to a URL".
  2. In the Redirect to box, enter the domain you wish to move to (no trailing slash), plus $S$Q - for example, http://www.developerfusion.com$S$Q
  3. Next, check the options that state the client will be sent to "The exact URL entered above", and "A permanent redirection for this resource"

And that's it! Now, what does this $S$Q do? These are basically tags that IIS will automatically replace - $S will be replaced with the subdirectory location (such as /images/show.aspx) and $Q will be replaced with the querystring (such as ?id=30).

You might be wondering why we can't just use $Q, and then turn off "The exact URL entered above" - but in this situation, you get your domain name, then the query string, and *then* the subdirectory location - which probably isn't what you wanted! For more information, check out this.

Published 18 January 2005 09:53 AM by James Crowley

Comments

# Dan said on 02 February, 2005 04:32 PM
Oh, this is brilliant (as they say in the UK -right?) This is exactly what I wanted for my website which has various domain names. I want everyone to start bookmarking just one of the domain names in case we decide to start getting rid of the old ones...
# TrackBack said on 27 March, 2005 02:24 PM
Como prometí, unos comentarios de como me fue con la migración de .Text a Community Server.
# Tip: Migrating content into Wordpress said on 18 January, 2007 04:10 PM

PingBack from http://web-professor.net/wp/2007/01/18/tip-migrating-content-into-wordpress/

# Work at home moms. said on 14 May, 2008 10:12 PM

Work at home moms. Work from home moms. Top work at home moms. Moms work from home. Amazon com work at home moms.

# Atif Aziz said on 16 August, 2008 09:08 AM

Ironically, the "for more information" at the end that points to IIS documentation is broken. ;)

Leave a Comment

(required) 
(required) 
(optional)
(required)