ImproperUsername
ImproperUsername

Reputation: 81

Web.config redirect one domain to non-https folder and another domain to https folder

I have a domain alias for my site. I would like to know how to redirect requests for domainA.ext to https://domainA.ext/folderA and requests for domainB.ext to http://domainB.ext/folderB

Presently I have the following rule to redirect all http requests to https but it redirects ALL requests to https:

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

It is Windows server 2008, but my cms is in PHP.

Upvotes: 2

Views: 1528

Answers (1)

cheesemacfly
cheesemacfly

Reputation: 11762

I can't think of something more simple than 4 different rules.

The 2 first ones for domainA.ext:

<rule name="Check path folderA" stopProcessing="true">
    <match url="^folderA" negate="true" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainA\.ext$" />
    </conditions>
    <action type="Redirect" url="https://domainA.ext/folderA/" />
</rule>
<rule name="Check SSL for domainA" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainA\.ext$" />
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>                         
    <action type="Redirect" url="https://domainA.ext/folderA/" />
</rule>
  • 1st rule: if the path doesn't start with folderA, then it redirects to https://domainA.ext/folderA/
  • 2nd rule: if HTTPS is off, it redirects to https://domainA.ext/folderA/

And the 2 next ones for domainB.ext:

<rule name="Check path folderB" stopProcessing="true">
    <match url="^folderB" negate="true" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainB\.ext$" />
    </conditions>
    <action type="Redirect" url="http://domainB.ext/folderB/" />
</rule>
<rule name="Check no SSL for domainB" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainB\.ext$" />
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>                         
    <action type="Redirect" url="http://domainB.ext/folderB/" />
</rule>
  • 1st rule: if the path doesn't start with folderB, then it redirects to http://domainB.ext/folderB/
  • 2nd rule: if HTTPS is on, it redirects to http://domainB.ext/folderB/

Upvotes: 3

Related Questions