Search code examples
http-redirectiisiis-10

redirect some domains to https and some to http in IIS


I redirect all requests to https with below rule but now I want to prevent redirection for some subdomains.

I redirected test.com to https://test.com, sub.test.com to https://sub.test.com But I don't want sub2.sub.test.com to be redirected.

 <rule name="https2" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Temporary" />
            </rule>

What should I do?

Thank you


Solution

  • You could try below rule:

    <rule name="http2" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^test.com$|^sub.test.com$" />
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
                </rule>
    

    this rule only redirects domain wich set in condition.