这是我最终使用的规则,比预期的要简单。
<rewrite>
<rules>
<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="mysite\.ca" />
</conditions>
<action type="Redirect" url="http://mysite.com/{R:1}" />
</rule>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="myfrenchsite\.ca" />
</conditions>
<action type="Redirect" url="http://myfrenchsite.com/{R:1}" />
</rule>
<rule name="No www 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.myfrenchsite)(.*)$" />
</conditions>
<action type="Redirect" url="http://myfrenchsite.com{PATH_INFO}" />
</rule>
<rule name="no www 2" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.mysite)(.*)$" />
</conditions>
<action type="Redirect" url="http://mysite.com{PATH_INFO}" />
</rule>
</rules>
</rewrite>