Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Created March 4, 2016 16:40
Show Gist options
  • Save greggnakamura/754d8f68c8b0c84cb2c9 to your computer and use it in GitHub Desktop.
Save greggnakamura/754d8f68c8b0c84cb2c9 to your computer and use it in GitHub Desktop.
web.config: Add 'www' to HTTP or HTTPS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Add www to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.site2\.com$" negate="true" />
<add input="{HTTPS}" pattern="On" />
</conditions>
<action type="Redirect" url="https://www.site2.com/{R:1}" />
</rule>
<rule name="Add www to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.site2\.com$" negate="true" />
<add input="{HTTPS}" pattern="Off" />
</conditions>
<action type="Redirect" url="http://www.site2.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment