Rewriting Non WWW to WWW URL (SSL Enabled Domain)

 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 http://domainname.com to http://www.domainname.com and https://www.domainname.com

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.
 

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Canonical Host Name" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="{MapSSL:{HTTPS}}www.example.com/{R:1}" redirectType="Permanent" />
            </rule>
        </rules>
        <rewriteMaps>
            <rewriteMap name="MapSSL" defaultValue="OFF">
                <add key="ON" value="https://" />
                <add key="OFF" value="http://" />
            </rewriteMap>
        </rewriteMaps>
    </rewrite>
<system.webServer>


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