Below is the code you need to enter in to your web.config file in order to redirect a domain to a sub-domain or vice versa.
WWW to non WWW:
<rewrite>
<rules>
<rule name="Remove WWW prefix" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.yourdomain\.com$" />
</conditions>
<action type="Redirect" url="http://yourdomain.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
*You will also need to change "yourdomain" to your actual domain on Lines 6 and 8.
Non WWW to WWW:
<rewrite>
<rules>
<rule name="Add WWW prefix" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yourdomain\.com$" />
</conditions>
<action type="Redirect" url="http://www.yourdomain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
*You will need to change "yourdomain" to your actual domain on Line 6 and 8.
Article ID: 1613, Created: 2/7/2019 at 2:19 PM, Modified: 3/6/2019 at 8:19 AM