I have a IIS server running sites using 2 domains with multiple sites on each. I'm trying to write a url rewrite rule that only affects the one site The domains is this
*.it.test.com
*.test.com
I have tried this rule but it seems to it do not seem to work - maybe I need a wildcard or something in the domian.
I'm trying to hit the subdomains of it.test.com
<rule name="Redirect to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" ignoreCase="true" matchType="Pattern" pattern="^it.test.com$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Temporary" />
</rule>
A couple of sites names could be this
bb.it.test.com
aa.it.test.com
cc.test.com
As far as I know, if you choose patternSyntax="Wildcard"
, the {HTTP_HOST}
in conditions
is also use wildcard to match.
So this is reason why pattern="^it.test.com$"
match failed. Wildcard is a special sentence, mainly including (*) and (?). Start with (^) and end with ($) is the usage of regular expressions.
Even you change patternSyntax="regular expressions"
, it will still fail because of ^. bb.it.test.com
is not start with it
but bb
.
Two solutions.
pattern="(.*).it.test.com$"
, but it only match bb.it.test.com aa.it.test.com
. pattern="(.*).test.com$"
will match both of them.pattern="*.test.com"
.