Skip to main content

IIS Rewrite Rule to redirect all non-secure http requests, to secure https requests.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="HTTPS Redirect" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*"/>
          <conditions logicalGrouping="MatchAny">
            <add input="{HTTPS}" pattern="off"/>
          </conditions>
          <action redirectType="Permanent" type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

<!-- ================================================================================================= -->
<!-- Setting up an HTTP/HTTPS redirect in IIS                                                          -->
<!-- https://www.namecheap.com/support/knowledgebase/article.aspx/9953/38/iis-redirect-http-to-https/  -->
<!-- ================================================================================================= -->

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule enabled="true" name="Redirect http to https" stopProcessing="true">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$"/>
          </conditions>
          <action redirectType="Permanent" type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>