Created
August 5, 2014 08:56
-
-
Save tcmorris/3e9808ec852cd421a1d7 to your computer and use it in GitHub Desktop.
Redirect rule to remove/force www
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<rewrite> | |
<rules> | |
<!-- Remove/force the WWW from the URL. | |
You need to install the IIS URL Rewriting extension (Install via the Web Platform Installer) | |
http://www.microsoft.com/web/downloads/platform.aspx | |
** Important Note | |
using a non-www version of a webpage will set cookies for the whole domain making cookieless domains | |
(eg. fast cdn-like access of static resources like css, js and images) impossible. --> | |
<!-- Use this to remove www --> | |
<rule name="Remove WWW" stopProcessing="true"> | |
<match url="^(.*)$" /> | |
<conditions> | |
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" /> | |
</conditions> | |
<action type="Redirect" url="http://example.com{PATH_INFO}" redirectType="Permanent" /> | |
</rule> | |
<!-- Or this to force www --> | |
<rule name="Force WWW" stopProcessing="true"> | |
<match url=".*" /> | |
<conditions> | |
<add input="{HTTP_HOST}" pattern="^example.com$" /> | |
</conditions> | |
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" /> | |
</rule> | |
</rules> | |
</rewrite> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment