HTTPS only for Azure Websites

1 minute read

In some situations you would like your Azure website to only work under HTTPS. By default a Azure website will work under HTTP and HTTPS. Today I was searching for a option how to disable HTTP traffic. Looking in de old and new portal did not help at all.

 

The next option was to rewrite the URL. You can if you need to rewrite the URL from your web.config file. If you place a “rewrite” element within the “system.webServer” element of your web.config file you can specify rules in order to rewrite your URL.

Take a look at my example for rewriting to HTTPS.

 

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect HTTP to HTTPS">
        <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
      </rule>
    </rules>
    </rewrite>
</system.webServer>

 

The rule is named “Redirect HTTP to HTTPS”  and matches all URLs. Based on the input conditions the rule will not be applied on HTTPS traffic.  The action will then rewrite the URL to HTTPS.

 

With help from:

Benjamin Perkins