Redirect www requests to non-www requests using the rewrite module

Web.config example of using the rewrite module to permanently redirect (301) www requests


How to create a Rewrite Rule
In the <system.webServer> node, add the following rewrite rule.
    <clear />
    <rule name="www_rule" stopProcessing="true">
      <match url="(.*)"/>
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="www." ignoreCase="true"/>
      <action type="Redirect" url="{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
This rule looks for any request with "www." and permanently redirects to the equivalent non-www url. The {REQUEST_URI} variable will preserve the original request's path. If your site accepts query string parameters, change the appendQueryString to true.

For further information, see the following:

URL Rewrite Module Configuration Reference