将mysite.ca/something/重定向到mysite.com/something/

时间:2013-09-01 19:23:31

标签: iis-7 url-rewriting

我正在运行一个IIS7网站,它有6个绑定。

  • mysite.ca
  • mysite.com
  • myfrenchsite.ca
  • myfrenchsite.com
  • mydevsite.mydevdomain.com
  • myfrenchdevsite.mydevdomain.com

我想以下列方式重定向我的域名:

  • mysite.ca/something/ - > mysite.com/something /
  • myfrenchsite.ca/somethingelse/ - > myfrenchsite.com/somethingelse /

我对IIS的重写语法不是很了解,我正在尝试一些事情,但我真的不确定规则应该是什么。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

以下是我最终使用的规则,比预期的简单。

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