Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force HTTPS on Azure and append URL

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>
like image 890
MK8 Avatar asked Sep 30 '14 00:09

MK8


1 Answers

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

like image 51
astaykov Avatar answered Nov 16 '22 13:11

astaykov