Steen
Steen

Reputation: 2887

IIS url rewrite to https for multiple domains, but not all

i have +10 domains on one solution, and about half of them have had an SSL certificate attached. I seem to have trouble creating ONE rule to make the correct ones being forced onto https.

I can to a rule for each of them, but feel this should have worked:

<rule name="HTTP to HTTPS redirect 1" patternSyntax="ECMAScript" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTP_HOST}" pattern="^www.domainNo1.dk$" />
      <add input="{HTTP_HOST}" pattern="^www.domainNo2.dk$" />
      <add input="{HTTP_HOST}" pattern="^www.domainNo3.dk$" />
      <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>

this leaving the domain4, domain5, etc. alone.

Unfortunately it does not kick in when I have more than one domain in the rule. I'm guessing it is the logical grouping that is probably default:

logicalGrouping="MatchAll"

But setting:

logicalGrouping="MatchAny"

will make the sites not work at all. After the redirect to https it continues to redirect the pages, resulting in "ERR_TOO_MANY_REDIRECTS".

I would have thought this was handled by

<add input="{HTTPS}" pattern="off" />

But no.

Hope anyone can help.

Upvotes: 0

Views: 619

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12854

You could use below rewrite rule to match multiple domains:

<rule name="http to https with multiple domain name" stopProcessing="true">
    <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="www.sample1.com|www.sample3.com" />
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>

enter image description here

Upvotes: 1

Related Questions