The trick is to combine the domains you want to match against into one rule with the or |
operator so that you only have one 'positive' rule and one 'negative' rule which should MatchAll
. E.g.:
<rule name="UK Host Name">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^company\.(co(\.uk)?|org|net|uk\.com)$" />
<add input="{HTTP_HOST}" pattern="^www\.company\.co\.uk$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.company.co.uk/{R:1}" />
</rule>
<rule name="France Host Name">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^company(-france)?\.(fr|com)$" />
<add input="{HTTP_HOST}" pattern="^www\.company\.fr$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.company.fr/{R:1}" />
</rule>
This might eventually give you a slight chance that your regular expression matches too many domain names. E.g. the pattern pattern="^company(-france)?\.(fr|com)$"
also matches company.com
which might not be desirable. In that case you have to be more specific and e.g. change the pattern to pattern="^company\.fr|company-france\.com$"
.