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



我试图将所有URL从主机,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>

看来我的模式是不正确的,因为当URL为www.host1.com/test.php时,它不会重定向,但只有www.host1.com。我该如何解决?

呢?看看这是否会得到您想要的。

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

最新更新