0

I have 2 separate sites. One site is within a subfolder of the main site. I need to force HTTPS to both sites but keeping the query string intact as users can enter the site from internal pages.

The issue I am having is when I try to add the IIS rewrite rule for the subfolder site it redirects to the main site.

The main site rule seems to be overriding the subfolder rule.

Main site rule:

<rule name="Force HTTPS" enabled="true">
    <match url="(.*)" ignoreCase="false" />
    <conditions>
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

Subfolder rule (in its own web.config file):

<rule name="Force HTTP" enabled="true" stopProcessing="true">
    <match url="(^subfoldersite/.*)" ignoreCase="true" />
    <conditions>
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

I have tried without a subfolder rule but same thing happens

puks1978
  • 3,667
  • 11
  • 44
  • 103

2 Answers2

0

You may want to check out this question's answer, in case it applies to your situation: Override an IIS rewrite rule for child site?

Community
  • 1
  • 1
0

Too late for this answer but I hope it may help someone. I just fixed this issue for my hosting.

You may use below settings.

Main Website Rule:

<rules>
    <rule name="Redirect to https" stopProcessing="true">
       <match url="(.*)" />
       <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
       </conditions>
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
    </rule>
</rules>

Subfolder Rule:

<rules>
    <clear />
</rules>
Chirag
  • 1,683
  • 2
  • 17
  • 26