Previous Next

Thread: Redirect rule that is SSL aware

Last post 09-05-2008 5:31 PM by ruslany. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 08-03-2008, 1:03 AM

    • cichanlx
    • Top 150 Contributor
    • Joined on 02-24-2004, 12:31 AM
    • Posts 22

    Redirect rule that is SSL aware

    Is it possible to have a single redirect rule that is SSL aware?  It would seem not given that I cannot capture the URL scheme (HTTP or HTTPS), and there is no server variable for it, to reference or back-reference it in the Rewrite URL.

    I want one rule that redirects both of the following:

    http://www.mysite.com/page to http://www.mynewsite.com/page

    https://www.mysite.com/page to https://www.mynewsite.com/page

    , Lee

  • 08-05-2008, 2:33 AM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 207

    Re: Redirect rule that is SSL aware

    You could capture the scheme by using the {SERVER_PROTOCOL} server variable in condition. This server variable contains the protocol together with version number (e.g. HTTP/1.1), so you would need to have a regex that captures only the protocol part. For example:

    <add input="{SERVER_PROTOCOL}" pattern="^(HTTPS?)"/>

    then use this in your substitution URL: {C:1}://yourservername.com

    http://ruslany.net
    Tags:
  • 08-05-2008, 3:51 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 207

    Re: Redirect rule that is SSL aware

    Ignore my previous post - the SERVER_PROTOCOL cannot be used for this because it contains HTTP/1.1 regardless whether SSL is used or not.

    http://ruslany.net
    Tags:
  • 09-05-2008, 2:24 PM In reply to

    Re: Redirect rule that is SSL aware

    I also want to know about a similar thing.

    Is it possible to have a single redirect rule that is SSL aware?  It would seem not given that I cannot capture the URL scheme (HTTP or HTTPS), and there is no server variable for it, to reference or back-reference it in the Rewrite URL.

    I want one rule that redirects the following:

    http://www.mysite.com/page to https://www.mynewsite.com/page

    Rahul Vats
  • 09-05-2008, 5:31 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 207

    Re: Redirect rule that is SSL aware

    Rule like this may help:

       <rule name="redirect" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAny">
                            <add input="{HTTPS}_http" pattern="^off_(http)$" />
                            <add input="{HTTPS}_https" pattern="^on_(https)$" />
                        </conditions>
                        <action type="Redirect" url="{C:1}://www.mynewsite.com/{R:1}"
                                             redirectType="Permanent" />
       </rule>

    However, this will not work on CTP version of URL rewrite module because of a bug. This will work in upcoming beta release of the module.

    http://ruslany.net
Page 1 of 1 (5 items)
Page view counter