301 Redirecting Multiple Domains

 This article applies only to Windows 2008-2012 servers with IIS7/IIS8 (sites hosted on our raptor13 or newer). It explains how to use the IIS Rewrite Module to direct incoming traffic for multiple domain name to http://www.domainname.com, a popular thing to do for SEO.

Step 1: Download the web.config file from your site root folder.

Step 2: Open this file in your favorite text editor and insert the following redirection code inside the <configuration> tags.

            <rule name="Redirects to www.domain.com" patternSyntax="ECMAScript" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^domain.*(com|net)$" />
                    <add input="{HTTP_HOST}" pattern="^(www.)?mydomain2.(com|net)$" />
                    <add input="{HTTP_HOST}" pattern="^www.domain.net$" />
                <action type="Redirect" url="http://www.domain.com/{R:0}" />

Condition Match Example:

domain.com (1st condition)
domain.net (1st condition)
www.mydomain2.com (2nd condition)
www.mydomain2.net (2nd condition)
mydomain2.com (2nd condition)
mydomain2.net (2nd condition)
www.domain.net (3rd condition)

Step 3: Save the file and upload it back to your FTP

If if the <system.webServer> already exists in your web.config place the code minus the <system.webServer> tags inside the existing tag structure.


Add Feedback