HTTPS only for Azure Websites

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

Related Posts

Restricting access to your Azure Web Application As you may know almost everything that is deployed to Azure is publicly available. As with Azure SQL Database you do not have a firewall available for...
Configure access to a private network for a Azure App Services On-Premise connections for Azure App Services can be created by using Hybrid Connections. Hybrid connections do not need any development or re-configu...
Extensions and Tips for deploying with Azure Resource Templates Working with Azure Services in different subscriptions means that the Azure Services need to run in different subscriptions. This often occurs when we...
Part 2 – Azure API Application to query the Azure SQL Database This post is the second in a series of three posts and will help you with the creation of identity pass-through authentication from a client applicati...
Part 1 – Azure SQL Database with Azure Active Directory Authentication This post is the first post in a series of three posts and will help you with the creation of identity pass-through authentication from a client appli...
Pass-Through Authentication with Azure Active Directory, Azure SQL, Azure API an... In situations you need to login to an application and use that identity to access an API (pass-through identity) and also get data from Azure SQL Serv...

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *