Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have an IIS7 web server with several sites running. Some of the sites are sub-domains of one domain and the others are totally separate domains. I want to use IIS re-write to redirect all the sub domain sites of one domain to https, but I want the other domains left as they are. For example I have the following sites on the same web server:

one.test.com, two.test.com, otherdomain.com

And I want to setup a global IIS rewrite to redirect http://one.test.com and http://two.test.com to https, but otherdomain.com should not be affected.

Here is what I have so far, and when I've tested the regex it seems correct but it is not redirecting the subdomain sites:

                <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
                    <match url="(.*)(\.test\.com)" />
                    <conditions logicalGrouping="MatchAny">
                    <action type="Redirect" url="https://{R1}{R2}" redirectType="SeeOther" />

Am I over complicating this or missing something obvious?


share|improve this question

1 Answer 1

You need to add conditions that match HTTP_HOST to your rule (the "url" variable in URL Rewrite doesn't include hostname).

    <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
        <match url="(.*)" />
            <add input="{HTTP_HOST}" pattern="(.+)\.test\.com" />
        <action type="Redirect" url="https://{C:0}/{R:0}" />

This rule should redirect all requests on *.test.com to HTTPS.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.