URL从一个主机重写到另一个主机

时间:2014-01-27 17:51:55

标签: iis url-rewriting rewrite

我正在尝试将主机host1(www.host1.com)中的所有网址重写为新的新主机host2(www.host2.com)。我希望host1的所有文件夹和子文件夹重定向到host2的主页面。这意味着www.host1.com/test.php应该重定向到www.host1.com

 <rule name="Test Redirect" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTP_HOST}" pattern="^(?:www\.)?host1.com" />
                </conditions>
                <action type="Redirect" url="http://www.host2.com/{R:0}" appendQueryString="false" redirectType="Found" />
            </rule>

似乎我的模式不正确,因为当网址为www.host1.com/test.php时它不会重定向,但只有当它只是www.host1.com时才会重定向。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这个怎么样?看看这是否会得到你想要的。

<rewrite>
    <rules>
        <rule name="CustomRule">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.newsite\.com$" negate="true" />
            </conditions>
            <action type="Redirect" url="http://www.newsite.com/{R:1}" />
        </rule>
    </rules>
</rewrite>