This question has been asked before and I've browsed the suggestions questions before asking it myself. Unfortunately I've not come across the answer I require.
I have rewrite in my Web.Config file for redirecting a TLD domain from HTTP to HTTPS. The problem I have is that it redirects the sub-domain sites as well. I only want the TLD to redirect and not the sub-domain sites.
For example I have www.example1.co.za and www.example2.com
I require http://www.example2.com to redirect to https://www.example2.com , but not http://a.example2.com or any sub-domain of www.example2.com
It must also keep the redirect rule for http://example1.co.za to redirect to https://example1.co.za
Here is my Config code:
<rules>
<clear />
<rule name="Redirect to SSL for Mass" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="example1\.co\.za$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://example1.co.za" />
</rule>
<rule name="Redirect to SSL for Pro" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="example2\.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://example2.com" />
</rule>
</rules>
EDIT
I tried adding another rule to exclude sub-domains. however I get en error :(
<rule name="Exclude Sub Sites from Pro HTTPS Rule" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^*\.example2\.com$" negate="true" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
</rule>
This rule will redirect:
http://www.example.com
to redirect to https://www.example.com
,
http://example.com
to redirect to https://example.com
<rule name="Check SSL" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www\.)?example\.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
</rule>
This regexp ^(www\\.)?example\\.com$
is filtering requests, which have host different than example.com
or www.example.com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.