0
votes

I am trying to force the use of http on all pages of our site with the exception of a checkout page. I have used the rewrite rule below but it doesn't work with the www sub-domain in the url.

If I use https://domain.com it successfully redirects to http://www.domain.com but if I try https with www nothing happens. Please note that there is also a canonical domain name redirect in place but this issue still happens without this rule.

<rule name="No-https" enabled="true" stopProcessing="true">
  <match url=".*" negate="false" />
  <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" />
  <conditions>
    <add input="{HTTPS}" pattern="on" />
    <add input="{URL}" pattern="CheckOut" negate="true" />
  </conditions>
</rule>

This has been driving me nuts all morning, I'm hoping someone with more experience of IIS rewrites can give me some help.

1

1 Answers

0
votes

Spent a few hours on a similar issue. In my case I'm redirecting traffic from http to https and I want to do the same where sub domains are in use, e.g. http://subdomain.mydomain.com rewrites to https://subdomain.mydomain.com. It seems that for IIS 7.5 at least you need to add a http binding in IIS for each specific subdomain or it will not be picked up by the catch all matching below.

    <rewrite>
        <rules>
            <clear />
            <rule name="Redirect to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>