【问题标题】:IIS Redirect olddomain.com/en-us/ABC to newdomain.com/ABCIIS 将 olddomain.com/en-us/ABC 重定向到 newdomain.com/ABC
【发布时间】:2021-07-14 09:10:15
【问题描述】:

我想在 web.config 中设置一个从 olddomain.com/en-us/abc/blahblahnewdomain.com/abc/blahblah 的重定向 意思是除了域名的变化,新的URL没有/en-us/,其他的都一样。 我从这里和那里拿起并想出了以下代码,但它不起作用。你能帮忙吗?

<rule name="Redirect New Site" enabled="true" stopProcessing="true">
<match url="^/en-us/(.*)$" />
  <conditions logicalGrouping="MatchAll">
  <add input="{PATH_INFO}" pattern="^/abc/(.*)" />
  <add input="{HTTP_HOST}" pattern="^olddomain.com/$" />
  </conditions>
  <action type="Redirect" url="https://newdomain.com/{R:1}" redirectType="Permanent" />
</rule>

【问题讨论】:

标签: iis url-rewriting


【解决方案1】:

对于这个要求,我在我身边测试它。您可以使用&lt;rule&gt;,如下所示:

<rule name="redirectRule1" enabled="true" stopProcessing="true">
    <match url="^en-us/(.*)" />
    <conditions logicalGrouping="MatchAll">
      <add input="{HTTP_HOST}" pattern="^olddomain$" />
    </conditions>
    <action type="Redirect" url="http://newdomain.com/{R:1}" />
</rule>

这是我这边的规则和测试结果。我的web.config 中的&lt;rule&gt; 是:

<rule name="redirectRule1" enabled="true" stopProcessing="true">
    <match url="^en-us/(.*)$" />
    <conditions logicalGrouping="MatchAll">
      <add input="{HTTP_HOST}" pattern="^localhost:49293$" />
    </conditions>
    <action type="Redirect" url="http://newdomain.com/{R:1}" />
</rule>

请注意我的旧域名是localhost:49293

然后当我请求 url http://localhost:49293/en-us/Upload 时,它将重定向到新的 url http://newdomain.com/Upload(没有en-us)。

=============================更新=========== =================

<rule name="redirectRule1" enabled="true" stopProcessing="true">
    <match url="^en-us/abc/(.*)" />
    <conditions logicalGrouping="MatchAll">
      <add input="{HTTP_HOST}" pattern="^olddomain$" />
    </conditions>
    <action type="Redirect" url="http://newdomain.com/abc/{R:1}" />
</rule>

【讨论】:

  • 谢谢你。因为我只想将一个特定文件夹(在本例中为 /abc/)中的所有内容重定向到新站点,同时保持其他所有内容不变。我想我们需要以某种方式声明路径信息
  • 嗨@Michelle 请检查更新规则是否满足您的要求?
猜你喜欢
  • 1970-01-01
  • 2021-01-14
  • 2019-01-27
  • 2011-05-30
  • 1970-01-01
  • 2020-02-29
  • 2016-01-20
  • 1970-01-01
  • 2021-09-16
相关资源
最近更新 更多