Post

Domain rewrites in IIS web.config

Using IIS URL Rewrite rules to consolidate multiple domain variants to a single canonical domain, preventing duplicate content SEO penalties.

When multiple domain names point to the same site — different TLDs, or www vs. non-www variants — search engines see them as separate sites serving duplicate content. The solution is to pick a canonical domain and redirect all others to it with a 301.

Add the following to web.config inside <system.webServer>:

<!-- START: Rewrite rules first added 03 October 2013 -->
<rewrite>
  <rules>
    <rule name="Redirect non-www to www" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^some-domain.co.uk$" />
        <add input="{HTTP_HOST}" pattern="^some-domain.com$" />
        <add input="{HTTP_HOST}" pattern="^www.some-domain.com$" />
      </conditions>
      <action type="Redirect" url="http://www.some-domain.co.uk/{R:0}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
<!-- END: Rewrite rules -->

In this example, some-domain.co.uk, www.some-domain.com, and some-domain.com all get permanently redirected to www.some-domain.co.uk.

Key points:

  • logicalGrouping="MatchAny" means the rule fires if any of the host conditions match
  • redirectType="Permanent" issues a 301 Moved Permanently — the correct status for SEO
  • {R:0} captures the full URL path so the redirect preserves the page being requested
  • stopProcessing="true" prevents subsequent rules from running after a match

Adjust the domain patterns and canonical URL to match your specific domains.

← Back to all posts