I have a Windows 2008 server running IIS7.5 using URL Rewrite.
I have a URL and want all permutations of this URL to redirect to a secure https version with www. So for example I want the following:
To redirect to:
I have set up 3 rewrite rules but unfortunately I cannot get https://mydomain.ext to redirect.
Here are the rewrites I use with the middle one not working. However I would prefer a single rule to cover all instances.
<!-- Redirect http non www to https www -->
<rule name="Redirect http://mydomain.ext to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.ext" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- Redirect https non www to http www -->
<rule name="Redirect https://mydomain.ext to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="https://mydomain.ext" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- Redirect http to https -->
<rule name="Redirect http to https" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>