Redirect Everything Except One Port [Answered]RSS

2 replies

Last post Jan 07, 2021 05:25 PM by Geoff44

  • Redirect Everything Except One Port

    Jan 06, 2021 04:57 PM|Geoff44|LINK

    This is my first time building out a web farm with high availability. Current environment is:

    2x ARR servers ("ARR01"/"ARR02")

    Server 2019 Core

    Shared Configuration

    URL Rewrite Module installed

    2x IIS servers ("IIS01"/"IIS02")

    Server 2019 Core

    Shared Configuration

    I have created a web farm containing IIS01/02 ("WebFarm"). Right now, everything is working as expected--I have two "catch-all" rules--one to redirect HTTP to HTTPS, and one to rewrite URLs to the WebFarm. Now, I want to put our F5 load balancers in front of the ARR servers. We want the F5 to be able to determine if the ARR servers are up/down. This is where I am having an issue. I created a site on the ARR servers using a custom port (8080). I created a rule with "Action = None" and to stop processing subsequent rules, but when I go to that URL (e.g. "http://ARR01:8080"), it still gets redirected.

    I'd like to avoid having to create a custom rewrite rule for every site/DNS entry, and instead "redirect everything, except port 8080". I've tried adding some checks to the HTTP-to-HTTPS and WebFarm rules to ignore port 8080, but that hasn't made a difference. If I disable the HTTP-to-HTTPS and WebFarm redirect rules, everything is fine. Does the "Stop processing subsequent rules" not behave in the way I'm expecting it?

    URL Rewrite Screenshot

    applicationHost.config excerpt:

    <rewrite>
        <globalRules>
            <clear />
            <rule name="F5HealthCheck_NoRedirect" stopProcessing="true">
                <match url="8080$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="None" />
            </rule>
            <rule name="HTTP-to-HTTPS" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
            </rule>
            <rule name="ARR_WebFarm_loadbalance" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="http://WebFarm/{R:0}" />
            </rule>
        </globalRules>
    </rewrite>

  • Re: Redirect Everything Except One Port

    Jan 07, 2021 06:48 AM|Brucz|LINK

    Hi Geoff44,

    When you test "Action=None", did you disable other rules? 

    If you disable other rules but request still redirect, it may be caused by cache in browser or ARR. 

    By the way, I think the rule of "Action=None" didnot work because  match url="8080$" is wrong. The pattern is used to match URI. If the URL is http://ARR01:8080/abc/asdf/fwef, the pattern will math "abc/asdf/fwef", not 8080. You can use fail request tracing to check that whether the pattern matches successfully.

    So if you want to match URL with 8080 port, you can use HTTP_HOST variables. It contains port.

     <add input="{HTTP_HOST}" pattern="(.*):8080" />

    Best regards,

    Brucz

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
  • Re: Redirect Everything Except One Port

    Jan 07, 2021 05:25 PM|Geoff44|LINK

    You were spot on! All rules are enabled and when hitting port 8080, no redirect happens. Thank you so much for explaining my mistake and how to correctly perform what I wanted. Sincerely appreciated!

    Edit, adding the working <rewrite> section in case it helps someone else in the future.

    <rewrite>
        <globalRules>
            <clear />
            <rule name="F5HealthCheck_NoRedirect" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="(.*):8080" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="HTTP-to-HTTPS" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
            </rule>
            <rule name="ARR_WebFarm_loadbalance" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="http://WebFarm/{R:0}" />
            </rule>
        </globalRules>
    </rewrite>