Azure – Redirect HTTP to HTTPS in Azure (With Load Balancer)

azurerewrite

We have 2 Web servers in Azure that are Load balanced. We just installed SSL in our these azure websites to convert it to HTTPS.

Now we want that any request coming in as HTTP should be changed/redirected to HTTPS connection.

So, I for testing I created a published website on my local machine, then added self signed SSL certificate to get a secure site. Then I used URL rewrite to direct my HTTP site to HTTPS. I used this in Web.config.

This works perfectly on my local published site.

But this fails on the Azure server and gives me an Internal Server Error.

Any ideas?

I used the following in Web.config for the URL rewrite

<rewrite>
<rules>     
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="Off" />
                <add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="SeeOther" />
    </rule>         
</rules>

Best Answer

I think we can use URL Rewrite to redirect HTTP to HTTPS. We can follow these steps to achieve this function.

  1. If you don’t have URL Rewrite, we can download it from Microsoft.You can find the links from google. When you install it successfully, you can see URL Rewrite in IIS.

  2. The site is bound by the following two protocols:443 80

  3. Configuring the URL Rewrite.

    enter image description here

    enter image description here

    The policy of the configure in the two fingures

  4. We test it.

    In Azure VM, we access http:// , it will redirect to https:// successfully.

Now, we should pay attention to configure in Azure.

  1. Web Server NSG rules.

    For Input rules, 80 and 443 should be allowed to access.

  2. Load Balance Set.

    I think we should set two load balance set, 80 and 443.

Maybe application gateway can also achieve this function.