Force domain.com to redirect to www.domain.com using IIS 6

If you have a SSL on your site chances are that you only want your visitors to go through your site on one particular domain. Let's say you own domain.com and you always want your visitors to go to www.domain.com when using your site. IIS 7 has a really cool rewrite module that you can use but IIS 6 users need to jump through some hoops to get this function working.

For this article I will assume that you have www.domain.com already setup on your server in IIS 6 and that you have setup your SSL to work on this domain. I will also assume that you have setup the host name for your domain to be www.domain.com, your IP address and domain.com.

Your first step is to remove domain.com from the allowed host list for this domain in IIS. To do this just right click on domain.com in IIS and select Properties. Next to the IP address of your domain click the Advanced button. Highlight the host header that has domain.com (no www.) and click remove. Click OK and apply to save and continue.

At this point you might want to rename domain.com in IIS to say domain.com (WWW) to make it clear that this setup of domain.com is for www.domain.com.

Next up add a new domain to IIS. You should name this as domain.com (no WWW) in IIS, again this is only to make it clear when you're looking through your list of domains that this setup is for domain.com without the www. subdomain. Set this up exactly the same as you did for www.domain.com but put domain.com as the host name. Once you have added domain.com to IIS go to its properties and select the Home Directory tab.

  1. Select Redirect to another domain (1).
  2. Remove the application name (2).
  3. Enter in the domain we want to redirect to. In this case it's www.domain.com and add on $S$Q at the end of the domain so that you are specifying to IIS to redirect to the correct folder structure on www.domain.com and to pass through the correct query string values as entered by the user (3).
  4. Tick the checkboxes for The exact URL entered above and Permanent Redirect (4,5).
  5. Click Apply and then OK (6,7).

If you now open your browser and type in domain.com it should automatically redirect you to www.domain.com! If you test with query string values you should see that these also carry through to www.domain.com.

Although this option is not an ideal setup as it duplicates your IIS domain list it will work for you. If anyone knows a better way to achieve the same results in IIS 6 let me know.

 

blog comments powered by Disqus

Get In Touch

Follow me online at TwitterFacebook or Flickr.

Latest Tweets