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>