Skip to content

Instantly share code, notes, and snippets.

@tcmorris
Created August 5, 2014 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcmorris/3e9808ec852cd421a1d7 to your computer and use it in GitHub Desktop.
Save tcmorris/3e9808ec852cd421a1d7 to your computer and use it in GitHub Desktop.
Redirect rule to remove/force www
<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