Setting Up 301 Redirects in IIS 6.0
OK, this is kinda geekly but important. Did you know that search engines will catalog mydomain.com and www.mydomain.com essentially as two different websites! Strange but true. And this is not a good thing for your SEO performance.
WARNING: The rest of this article is pretty geeky. Read on at your own risk!
When you have links back to your site from other sites, search engine search results and other places you cannot always control what URL people are using to get to our site. The search engines will index based on the total URL not just the top-level domain — meaning they catalog mydomain.com and www.mydomain.com separately.
In effect, this can split your SEO results into two buckets, diluting your ranking in the search engines.
One way to deal with this is at the Web server level by creating something called a 301 Redirect (for more detail on this click here). This is fairly easy to do on a Linux/Apache server by configuring the .htaccess file for the site. Lots of instructions exist on the Web for doing this.
Seting Up 301 Redirects in IIS for Existing Websites
Our company has both Linux and Windows web servers so we have to do this in both environments.
Unfortunately, doing this in IIS is a bit more complex than editing a configuration file. The outline below is written for someone who has experience administering IIS on a Windows web server. I am assuming here a certain level of IIS knowledge and have not included basic “how does IIS work” details.
I’ve worked out a process for setting up a 301 redirect for a production site that already exists under IIS.  Here you go:
- In IIS create a new site and name it ‘mydomain.com – redirect’.
- Set the host header for this site to ‘mydomain.com.’
- When you get to the end of the new site wizard, you’ll get an error and the new site will not be running. Ignore it and click Finish.
- Now, go to the properties for the site you just created and do the following:
- Turn off logging. (You don’t need it. Nothing is running under this URL so there is nothing to log.)
- At the Home Directory tab click on “A redirection to a URL.”
- In Redirect put: http://www.mydomain.com$S$Q
(Note: Do not put a trailing slash after the ‘.com’. The ‘$S$Q’ is IIS code. More on this below.)
- Check these two boxes: (1) The exact URL … and (2) A permanent redirection.
- Change the application name to the name you gave this site in the first step above. (Optional.)
- Click OK.
- Go the IIS properties for the existing site.Â
- Rename it to www.mydomain.com.
- Click on the Advanced tab and delete the host header for mydomain.com, leaving the one for www.mydomain.com.Â
- Click OK twice.
- Start up the redirect site.
- Test it, and you’re done!
If you’ve made it this far without falling asleep you probably know something about IIS!
I did a bunch of research on the web on this issue but did not find the simple answer as above. It was probably out there somewhere, but I did not run across it. So I decided to post this in hopes of saving others the hassle I had.
What is the $S$Q For?
As noted above this is “IIS code.” It solves a particular problem. If you don’t have this code at the end of the URL you are redirecting to, the redirect will just bring up the homepage of the domain its being directed to.
So let’s say you’ve got some legacy HTML pages with image and other links in which the URL being used in the HTML uses the domain that is now being redirected. Here’s an example of what I mean:
Legacy URL: http://mydomain.com/images/mybanner.jpg.
If you’ve set up a redirect for ‘mydomain.com’ and not used the IIS code as shown above, this URL will kick to to www.mydomain.com and your image will not load!
The solution is to put the IIS code at the end of the domain being redirected to exactly as shown above.
Video Tutorial
A few days after I wrote this post I came across a great video tutorial that shows exactly how to do this using screen shots of IIS. Check it out here: IIS tutorial video.
OK, that’s it. Enjoy!
8 Comments

June 1st, 2009 at 11:10 am
Your blog is so informative
June 9th, 2009 at 8:43 am
Thanks John. Been looking for a step-by-step on this for a little while.
June 9th, 2009 at 9:03 am
Hey Joel,
Glad you liked it and if you haven’t already done it, sign up for our RSS Feed, we’ll keep em coming if you’ll keep reading them and finding the information useful.
Best,
Jason
June 9th, 2009 at 6:21 pm
Very nice information. Thanks for this.
June 12th, 2009 at 12:23 pm
The article is usefull for me. I’ll be coming back to your blog.
July 13th, 2009 at 5:04 am
Very useful info.. Will come back.
July 14th, 2009 at 1:09 pm
Seriously? Anyone familiar with IIS already knows how to do this. Anyone who doesn’t should not be administering a server.
July 15th, 2009 at 8:49 am
In a perfect world I would totally agree with you. Perhaps you’ve not worked with small businesses, which form our main customer base. They often cannot afford full-service hosting or host in-house. There are a lot of people out there who find themselves managing Windows Servers with IIS who are not well trained on all the functions of IIS. – John