Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:,,

And I want to setup a global IIS rewrite to redirect and to https, but 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

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 * 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.