Reputation: 2227
I have a rule to redirect my primary site to https and a test site to a test link as below
<rules>
<rule name="One" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="site.co.uk"/>
<add input="{HTTP_HOST}" pattern="^www.site.co.uk"/>
</conditions>
<action type="Redirect" url="https://www.site.co.uk/{R:0}"/>
</rule>
<rule name="Two" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^testing.domain.co.uk"/>
</conditions>
<action type="Redirect" url="http://testing.domain.co.uk"/>
</rule>
</rules>
I thought everything was working (each site was redirecting as required) until i ran a report and it seems if a user types in www.site.co.uk it displays the http version and not https - i have an entry for that <add input="{HTTP_HOST}" pattern="^www.site.co.uk"/>
which i thought was resolving this issue but it isnt.
How could i ensure my primary site with and without www can be redirected to the https version but also have my test site going to the test URL i have set?
Upvotes: 0
Views: 46
Reputation: 12844
There is one mistake in your rule you forget to add the HTTPS pattern off because of that host www.site.co.uk is facing too many redirect errors.
Try below rule:
<rule name="One" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="www.site.co.uk|site.co.uk" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.site.co.uk/{R:0}" />
</rule>
you no need to add the second rule.
Upvotes: 1