I'm trying to force HTTP to HTTPS on an Azure Web Site using a web.config URL rewrite rule. I'd like a rule which encompases both of the following scenarios:
HTTP: //site.domain.com/sitefolder to HTTPS: //site.domain.com/sitefolder
HTTP: //site.domain.com/sitefolder/default.aspx to HTTPS: //site.domain.com/sitefolder/default.aspx
If I follow this guide I can force HTTP to HTTPS but the URL changes to HTTPS: //site.domain.com without the /sitefolder or /sitefolder/default.aspx appended.
This is what I've got at the moment. HTTPS is forced, but the full URL is not included:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="Off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
This is the simple rule that makes correct redirect to HTTPS on Azure WebSites:
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
You can test it here: http://double.azurewebsites.net (take the note on the HTTP in the link) I don't have any other rules defined here. The rule above correctly redirects to deep links, i.e. http://double.azurewebsites.net/Home/About
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With