如何将所有请求重定向到 IIS 中的另一台主机

How to rediret all requests to another host in IIS

我想将所有请求从旧域重定向到新域。例如:

From:    oldhost.com/app1/houses?city=springs
To:      newhost.com/app1/houses?city=springs

我尝试使用基本的“HTTP 重定向”和“URL 重写”模块,结果相同。重定向仅在有限的范围内起作用,只要第一个路径段之后没有任何内容:

oldhost.com/app1 - works
oldhost.com/app1/houses?city=springs - does not work

这是尝试的 URL 重写规则:

   <rule name="rule1" enabled="true" stopProcessing="true">
          <match url=".*" />
          <action type="Redirect" url="https://newhost.com/{C:1}" logRewrittenUrl="true" />
          <conditions>
               <add input="{HTTP_HOST}" pattern="oldhost.com(.*)" />
          </conditions>
    </rule>

你可以试试这条规则:

<rule name="test">
  <match url="^(.*)$" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^oldhost.com$" />
    </conditions>
  <action type="Redirect" url="https://newhost.com/app1{R:1}" />
</rule>

使其适用于以下规则:

   <rule name="my_redirect" enabled="true" stopProcessing="true">
                    <match url=".*" />
                    <action type="Redirect" url="https://newhost.com/{R:0}" logRewrittenUrl="true" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="oldhost.com" />
                    </conditions>
   </rule>