0
votes

URL Rewrite rule for redirecting from http to https:

<rewrite>
    <rules>
        <rule name="http to https" enabled="false" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
    </rules>
</rewrite>

However, when you go directly to a subfolder like http://www.example.com/employees via an old bookmark or by typing the address into the browser, it doesn't redirect to https://www.example.com/employees but stays on http://www.example.com/employees.

Oddly enough, we have the same rewrite rules for a dev site, and it will redirect from http://dev.example.com/employees to https://dev.example.com/employees.

Very strange. Any ideas?

1

1 Answers

0
votes

This is what I use - I add it to the applicationhost.config file, so it's at the global level. It's a little different then yours, I run many different sites and never have the issue you're describing doing it this way.

  <rule name="Root Redirect to HTTPS" enabled="true" stopProcessing="true">
     <match url="(.*)" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
           <add input="{SERVER_PORT}" pattern="^80$" />
           <add input="{HTTP_HOST}" pattern="example\.com$" />
        </conditions>
     <action type="Redirect" url="https://www.example.com/{R:0}" />
 </rule>