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

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...
Azure Function CI – 3. Deploying the Azure Function from the Build within VSTS This post is the third and last one in a series of posts and will help you by deploying a CI build for a Azure Function. Prerequisites This blog post ...
Azure Function CI – 2. Create a CI Build for the Azure Function This post is the second one in a series of three posts and will help you by creating a CI build for a Azure Function. Prerequisites This blog post i...
Preview of the Policy Management UX Azure Resource Manager policies provide the ability to manage risks within a Azure environment. To implement this so called policies ca...

2 comments

Leave a Reply

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