Library code snippets

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.

Comments

  1. 28 Jun 2005 at 12:07

    this is very helpful.


    however, is it possible to set up multiple 301 redirects without having to use a separate website for each?


    ie, currently if i have 200 .com websites on a server, do i have to add a further 200 for their .co.uk counterparts?


    this might seem like an unlikely scenario but it's a situation i'm faced with, so i'd most appreciate some advice!!


    thank you..

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Permanent 301 Redirect with QueryString in IIS.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • Behind the Scenes at Microsoft.com

    Learn how the Microsoft.com operations team meets the demands for one of the top 5 websites on the Internet today. The team supports the server product teams at Microsoft by "dogfooding" products such as Windows Server 2008, SQL Server 2008 and IIS7 years before being released to custo...

Events coming up

  • Dec 9

    Internet Information Services 7.0 for ASP.Net Developers

    Glasgow, United Kingdom

    One of the biggest and best new features of Windows Server 2008 and Windows Vista is Internet Information Server 7.0.  IIS 7.0 is the latest and most significant release of Microsoft's Web Server. With this release comes a new extensibility model which gives developers more options than ever before, more diagnostic tools with which developers can debug and locate issues. During the session Andrew will investigate the new architecture, look at extending, configuring and developing for IIS7, ta...