Rewrite URL- redirection from http to httpsRSS

7 replies

Last post Jul 16, 2019 04:55 PM by Chris Becke

  • Rewrite URL- redirection from http to https

    Jul 15, 2019 06:59 PM|Divya T|LINK

    Hi,

    For one of our websites, the site works for both http and https. I'm trying to set up URL redirection so that http lands to https.

    Web config info:


    <rule name="DecomURLredirection-http to https" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAny">
    <add input="{HTTPS}" pattern="Off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" logRewrittenUrl="false" redirectType="Found" />

    Even though I set up redirection, still http lands to same URL and no redirection effect is noticed. Tried redirect url as https://{HTTP_HOST}/{R:0} but still does not help.

    Can someone guide here?

    Thanks,
    Divya

  • Re: Rewrite URL- redirection from http to https

    Jul 15, 2019 07:51 PM|Chris Becke|LINK

    You know - this doesn't address this question - how to use ARR to do this, but there is a stand alone HTTP Redirect module dedicated to, well, redirects.

    To use it all you do is create 2 sites, one with https bindings, and one with http bindings and HTTP Redirect...

    As to your issue, nothing really jumps out, other than this sites horrible quoting and your avoidance of regex :P

    All I can suggest is, rewrite to example.com and remove the condition so it should always fire and see that the rule is actually firing, and then add bits back until it breaks again.

  • Re: Rewrite URL- redirection from http to https

    Jul 15, 2019 09:10 PM|Divya T|LINK

    Chris,

    I'm afraid that we might not be able to create different sites for http and https as this site has dependency on other applications.So, we were considering Rewrite URL.

  • Re: Rewrite URL- redirection from http to https

    Jul 16, 2019 02:52 AM|Able|LINK

    Hi Divya T,

    According to your description,it seems that you want to use redirect rule to redirect any http request to https .So I suggest that you could  first create two sites ,one use http bindings and other use https bindings then you could create redirect rule as below:

     <rule name="HTTP to HTTPS Redirect" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll">
                            <add input="{HTTPS}" pattern="^off$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
          </rule>
     

    Best Regards

    Able

    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Rewrite URL- redirection from http to https

    Jul 16, 2019 04:07 AM|Chris Becke|LINK

    Ah. The point is the HTTP site would simply be an empty placeholder that exists purely to hold the HTTP Redirect configuration.

  • Re: Rewrite URL- redirection from http to https

    Jul 16, 2019 04:52 AM|bangon2006|LINK

    Creating the same 2 pages all, is the only other http & https a good solution?

  • Re: Rewrite URL- redirection from http to https

    Jul 16, 2019 03:54 PM|Divya T|LINK

    Hi,

    Can you recommend an alternate option instead of creating another http site?

    Would need to share few more details, so it might help to understand the scenario here:

    The site URL is available as one of the virtual application under default website, with many other applications. This application is linked with another tool called Symantec workflow, so this is as an UI interface for workflow developed in Symantec, so the application has other dependencies within the tool.

    Also, noticed that with URL redirect, the HTTP redirection to HTTPS works on local server but not working remotely.

  • Re: Rewrite URL- redirection from http to https

    Jul 16, 2019 04:55 PM|Chris Becke|LINK

    In order for the two site approach to work you need 

    "Http Site" 

    with a physical directory of - say - `D:\Sites\HttpSite`

    This directory would contain ONLY a web.config and no other files at all.

    This site would have _all_ the port 80 bindings to localhost and to the site name.

    And it would have an ARR redirect rule, or HTTP Redirect module, the rewrote all requests as https: requests

    "Https Site"

    would be your usual physical directory, with applications and vdirs as normal.

    This site would have NO http bindings, it would simply serve your site's applications as https.

    All the bindings on this site should be "*" or "All Addresses", NOT "127.0.0.1" as the latter will only accept local connections and would explain your behaviour.