I have an issue with the following setup.
- Server: Windows Server 2016
- Server Host: Google Compute Engine
- My instance is running behind a Load Balancer (and SSL is attached at the Load Balancer level).
I have a site on www.example.org. I want the web.config to 301 redirect:
- non-www to www
- http:// to https://
I have the following rules in web.config:
<rewrite>
<rules>
<clear />
<rule name="Force WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^(www\.)(.*)$" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.org/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" negate="true" pattern="^ON$" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.org/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
My problem is that the HTTPS rule results in an infinite loop. My theory is that this is down to the load balancer. I'm redirecting at 'site' (/server) level and it's looping back to the Load Balancer and everything is going "a little kaka" :)
Can anyone advise how/if it is possible to enforce HTTPS at the Load Balancer level on Google Compute Engine?!
I'm not amazingly competent at executing things in console (if that is the way to go) so any help would be greatly appreciated.