Thursday, 15 July 2010

Directing all visits to the www subdomain using IIS7

Your SEO champion will no doubt be banging his fists on his desk if you've built a site that allows users to view the same content on http://mysite.com as well as http://www.mysite.com

What he or she will be demanding is that one of them permanently redirects the user (with a 301 status) to the other. So how do you do this? Well, there might be several ways but this is the way I do it. For this example I'm going to be sending visitors from mysite.com to www.mysite.com.

Remove the 'mysite.com' entry from the bindings of your website but keep the 'www.mysite.com' entry. Create a new website and call it 'mysite.com redirect' or something similar. Add a binding to this for 'mysite.com'. This will then accept incoming visits to 'mysite.com'. Now click on the 'HTTP Redirect' icon:

and configure the site to redirect to 'http://www.mysite.com' with a Permanent(301) setting like below:


This will also honour any deep links to your site. For example if a user goes to http://mysite.com/whatever.aspx?whateverParam=whateverValue they will be redirected to http://www.mysite.com/whatever.aspx?whateverParam=whateverValue

UPDATE: on some machines you may not see the 'http redirect' icon. If this is the case go to the IIS section in 'Server Manager' and you'll probably see the role service isn't installed. You can install it easily from here.

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!