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…
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: