Redirecting to non-www using the Web.config
You can always use IIS to explicity set up a redirect, but I find that these types of configurations are best done in the Web.config, since they are (1) more portable, (2) have the ability to be stored in source control, and (3) can be included in Web.config transformations if you want to get all fancy!
Here’s what you need to add to your Web.config:
<rewrite>
<rules>
<rule name="Redirect to non-www" stopProcessing="true">
<match url="(.*)" negate="false"></match>
<action type="Redirect" url="http://domain.com/{R:1}"></action>
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true"></add>
</conditions>
</rule>
</rules>
</rewrite>
Note: You’ll need to make sure that for redirecting a site like www.example.com to example.com, you’ll need to make sure that you’ve configured both of those domains to point to your website. If you never set up the www. site to point to your host, IIS and your Web.config will never be hit to do a redirection.
Collect Lost SEO
And that’s it! These redirects have huge effects on what I call “accidental” SEO. All over the internet you’ll find people in the habit of hand-linking to websites, and we’ve got a bad habit of just assuming www and non-www links are inter-changeable, when they’re not. Setting up these redirects will ensure you get credit for all (or many, many more) of the links to your site that are out there on the web.