Thursday, April 23, 2015

Redirect http request to https on Microsoft Azure website

If you want force user to use https then you can create a redirect by following steps. Example is giving for Azure websites but it is possible in Azure Cloud app in many other way as it is more flexible.

Step 1:

Open you Azure portal go to you web app and on top menu choose Configure scroll down to certificates as show in figure.
Remember you need a valid SSL certificate for https otherwise it will show in red and it will be not trustworthy. Upload your certificate.
Go to ssl bindings section and select your domain, choose your SSL certificate to for requirement in case of multiple domains and certificates and then choose IP Based SSL.




Step 2:

Go to your web.config. Make sure choose the right one in case of multiple configs available.
Then paste this code.


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


Step 3:

Try!

If you want more detail step by step information please refer to source below.

Source: http://azure.microsoft.com/en-gb/documentation/articles/web-sites-configure-ssl-certificate/

No comments:

Post a Comment