I'm trying to redirect my site from WWW -> root.
http://www.example.com -> http://example.com https://www.example.com -> https://example.com
i've used the following rewrite rules:
<rule name="CanonicalHostNameHttp" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
This works fine:
- I enter http://www.example.com, it redirects to http://example.com
- http://example.com then redirects to https://example.com
This fails:
- I enter https://www.example.com
- It never redirects to https://example.com
- And as a result it gives me a certificate error (because my certificate is for example.com not www.example.com)
What am I missing???