Back to Posts

Azure website always on HTTPS

Vincent Wesker in Azure

Out of the box your Azure website is available on HTTP and HTTPS. It's nice to have a HTTPS option by default but there are a lot of usecases to where you want to load your Azure website on HTTPS by default and not on HTTP, or even only on HTTPS.

If you want to do this, the Azure portal will not help you. It's not possible to flip a switch and enable this. To change this you need to change your web.config.

In the system.webServer at the following snippet.

<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>  

Now your site will alway load on HTTPS. When a HTTP request is the request is redirected to HTTPS with a 301 code

alt

SharePoint O365 Dev | Azure | Working @ Mavention

Read Next

Gulp tasks in Visual Studio