0
votes

Windows Server 2012

I have 1 IIS container with 4 different URLs for one domain and 2 domains in total as below (set with the bindings)

www.site1.com site1.com www.site1.co.uk site1.co.uk

www.site2.com site2.com www.site2.co.uk site2.co.uk www.site1.com - is the primary domain, meaning any combination of the URLs above must take the user to www.site1.com or www.site2.com

I have the below rule which takes these sites to the primary URL

<rule name="PrimarySite" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="site1.co.uk" />
        <add input="{HTTP_HOST}" pattern="www.site1.co.uk" />
        <add input="{HTTP_HOST}" pattern="site1.com" />
      </conditions>
      <action type="Redirect" url="http://www.site1.com/{R:0}" />
    </rule>

I now would like the same but for HTTPs so added a new rule (just for site 1 but i would do the same for site 2).

    <rule name="site1HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions trackAllCaptures="true" logicalGrouping="MatchAny">
                  <add input="{HTTP_HOST}" pattern="site1.co.uk" />
                  <add input="{HTTP_HOST}" pattern="www.site1.co.uk" />
                  <add input="{HTTP_HOST}" pattern="site1.com" />
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{C:1}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent"/>
            </rule>

When i add this i receive a redirecting loop error and have tried different combinations but it just doesnt seem to work.

What have i missed off (I have to rules in total)?

1
Enable FRT so that you can learn how your rules run, docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/…Lex Li

1 Answers

0
votes

Use MatchAny for 3 {HTTP_HOST} and {HTTPS} will mess up the redirection logic.

You can combine 3 conditions into one so that {HTTP_HOST} and {HTTPS} can be used with "MatchAll" side by side.

<rule name="test">
       <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="(site1|site2)\.(com|co.uk)" />
            <add input="{HTTPS}" pattern="^off$" />
        </conditions>
      <action type="Rewrite" url="https://{HTTP_HOST}{REQUEST_URI}" />

Best regards, Sam