0

I had a url rewrite rule in the web.config of one of the sites on our server. But we are implementing a server farm with sites on the same physical server to enable "hot swap" deployments, as outlined here.

I found this link, which seems like it should work as it is redirecting first, so it shouldn't hit the re-write rule...then as the request comes back as an HTTPS request so the first rule would be bypassed, the farm rewrite should get execute. But I get the dreaded ERR_TOO_MANY_REDIRECTS error.

I've tried moving the rewrite rule from web.config to the applicationHost.conf, same error.

What am I missing?

Secondary question: Would the web.config take precedence to the applicationHost.config rules?

Web.congif rewrite rule:

<rewrite>
  <rules>
    <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="Found" />
    </rule>
  </rules>
</rewrite>

applicationHost.config rewrite rule:

<rule name="Route https test to server farm" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="test.com" />
        <add input="{SERVER_PORT}" pattern="443" />
        <add input="{HTTPS}" pattern="ON" />
        <add input="{SERVER_PORT}" pattern="^(800.*)$" negate="true" />
    </conditions>
    <action type="Rewrite" url="http://test-farm/{R:0}" />
</rule>

Then moved the web.config rule to applicationHost.config

<rule name="Redirect to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="test.com" />
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>

<rule name="Route https test.com to server farm" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="test.com" />
        <add input="{SERVER_PORT}" pattern="443" />
        <add input="{HTTPS}" pattern="ON" />
        <add input="{SERVER_PORT}" pattern="^(800.*)$" negate="true" />
    </conditions>
    <action type="Rewrite" url="http://test-farm/{R:0}" />
    </rule>
</globalRules>

Site Binding Rules:

<site name="test-Prod-A" id="11" serverAutoStart="true">
    <application path="/" applicationPool="test-Prod-A">
        <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\test-Prod-A\website" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8001:" />
<binding protocol="https" bindingInformation="*:8002:" />
    </bindings>
</site>
<site name="test-Prod-B" id="12" serverAutoStart="true">
    <application path="/" applicationPool="test-Prod-B">
        <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\test-Prod-B\website" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8003:" />
        <binding protocol="https" bindingInformation="*:8004:" />
    </bindings>
</site>
<site name="test-Prod-Farm" id="13">
    <application path="/">
        <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot" />
    </application>
    <bindings>
        <binding protocol="https" bindingInformation="*:443:test.com" sslFlags="1" />
        <binding protocol="http" bindingInformation="*:80:test.com" />
    </bindings>
</site>

Farm bindings:

<webFarms>
    <webFarm name="test-farm" enabled="true">
        <server address="test-a" enabled="true">
            <applicationRequestRouting httpPort="8001" httpsPort="8002" />
        </server>
        <server address="test-b" enabled="true">
            <applicationRequestRouting httpPort="8003" httpsPort="8004" />
        </server>
    </webFarm>
</webFarms>
crichavin
  • 121
  • 1
  • 5
  • First check if your rewrite rules lead to the redirection loop, https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules and then check the web apps (some apps can redirect internally back to HTTP). – Lex Li Jul 15 '20 at 00:24
  • @LexLi thanks. Our app wouldn't internally route back to HTTP, but I'm in the process of implementing the tracing. But I also was wondering if the ARR to the Server Farm would trigger the SSL redirect as it is routing to `` note the url in this is `http`, not `https`. I couldn't really find anything out about that and tried changing it to `https`, but got a 502 error when I did. – crichavin Jul 15 '20 at 00:56
  • @LexLi I added failed request tracing, but really can't determine what it is saying. The last line is: `BytesSent="477", BytesReceived="612", HttpStatus="301", HttpSubStatus="0"` is the 301 a problem? – crichavin Jul 15 '20 at 02:50
  • Hints: 1) Use browser's developer tools to analyze how many redirection responses it receives (that leads to the error). 2) Review FRT logs to confirm each of the responses. 3) Learn from FRT logs who issued each of the responses (URL Rewrite module, or your web app, or something else). That usually reveals the culprit. – Lex Li Jul 15 '20 at 03:36

0 Answers0