How do can I code a rewrite rule in IIS 8 so that all traffic points to https://www.*.com from http://*.com?

118 Views Asked by At

I have the following root level URLs where people could possibly go:

1. http://example.com
2. http://www.example.com
3. https://example.com
4. https://www.example.com

How can I ensure that 1, 2, and 3 always redirect to 4 with a rewrite rule in IIS 8? Of course, it should keep whatever secondary information is attached (e.g. /images/myfile.jpg?query=string&another=string)

1

There are 1 best solutions below

0
On

You can try this rule

<rewrite>
  <rules>        
    <rule name="example.com to www.example.com" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="www.example.com" negate="true" />
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://www.example.com/{R:1}"
              redirectType="Permanent" />
    </rule>
  </rules>
<rewrite>