2

I've been using the following pattern to set up directory structure for my main site and subdomains:

A. Each site is in its own subfolder, including the main site so that I have something like

\wwwroot
     \main
     \subdomain1

B. There's only 1 file in wwwroot. A web.config file with the following

<configuration>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
        <rules>
            <rule name="Rewrite to folder1" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www.MyMainDomain.com$" />
                </conditions>
                <action type="Rewrite" url="main/{R:1}" />
            </rule>
            <rule name="subdomain1.MyMainDomain.com to sub folder" enabled="true" stopProcessing="true">
                <match url="(.*)" ignoreCase="true" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTP_HOST}" pattern="^subdomain1\.MyMainDomain\.com$" ignoreCase="false" />
                    <add input="{PATH_INFO}" pattern="^/subdomain1($|/)" negate="true" />
                </conditions>
                <action type="Rewrite" url="\subdomain1\{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

How do I add https redirect to only the subdomain?

What's the best way to debug what is being rewritten/redirected?

Steve Wash
  • 986
  • 4
  • 23
  • 50
  • did you get this to work. I have the same problem and not sure how to handle it. The only difference is I don;t have a "main" but just need to redirect example.com/subdomain1 to https://subdomain1.example.com/subdomain1 – NoBullMan Feb 25 '17 at 22:08

1 Answers1

1

I am not sure what the best way to debug rewritten/redirected traffic.

In your condition you should be checking for if it is an http request:

<add input="{HTTP}" negate="true" pattern="^ON$" />

or checking for the lack of https request:

<add input="{HTTPS}" negate="true" pattern="^OFF$" />

Also, try changing the line with type="rewrite" from a rewrite to a permanent redirect, that way the browser get the proper 301 response code.

<action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent" />
Tsangares
  • 780
  • 1
  • 9
  • 27