Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward http to https in Azure

Tags:

azure

We have a deployment on Azure with a Web Role that uses https. Since this is the only way we would like our users to access the system, we want to forward users that visit the http version to the https version.

We have tried the recommendations here.

Namely, we added the following to our web.config:

<system.webServer>
<rewrite>
  <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

However, this doesn't seem to work. Does anybody have any idea how to accomplish this? It seems like it would be a common request...

like image 870
kbmax Avatar asked Aug 10 '11 20:08

kbmax


People also ask

How do I enable HTTPS in Azure application gateway?

Select HTTP settings from the left-side menu. Azure automatically created a default HTTP setting, appGatewayBackendHttpSettings, when you created the application gateway. Select appGatewayBackendHttpSettings. Under Protocol, select HTTPS.

Which will redirect to Azure portal?

Redirection protocol The most common use cases of the redirect feature, is to set HTTP to HTTPS redirection. HTTPS only: Set the protocol to HTTPS only, if you're looking to redirect the traffic from HTTP to HTTPS. Azure Front Door recommends that you should always set the redirection to HTTPS only.


1 Answers

Smarx just made a blog post about this a couple of minutes again ;)

http://blog.smarx.com/posts/redirecting-to-https-in-windows-azure-two-methods

In case the site goes down here is a summary:

IIS URL Rewrite

If you’re not using ASP.NET MVC but are using IIS (as in a web role), you can use the URL Rewrite module, which is installed by default. Using this module to redirect to HTTPS is fairly trivial and documented elsewhere, but getting everything to work properly in the local compute emulator is non-trivial. In particular, most examples you’ll find assume that HTTP traffic will always be on port 80, which isn’t always the case when testing under the compute emulator. Here’s a rule that seems to work locally and in the cloud:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect to HTTPS">
        <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          <add input="{URL}" pattern="/$" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
        <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
      </rule>
    </rules>
  </rewrite>
like image 199
Kevin Cloet Avatar answered Oct 14 '22 11:10

Kevin Cloet