【问题标题】:Redirect all subdomains to new domain将所有子域重定向到新域
【发布时间】:2019-02-04 19:40:15
【问题描述】:

我想使用 web.config 规则将所有流量重定向 (301) 到新域,但该站点还处理越来越多的子域列表,这些子域也需要重定向。

如何为以下内容编写规则?

  • 旧域名是 foo.com
  • 新域是 bar.org
  • 域 (foo.com) 之前和之后的所有内容都需要重定向到新域:
a.foo.com -> a.bar.org
b.foo.com -> b.bar.org
c.foo.com/some-page -> c.bar.org/some-page
d.foo.com/some/other/page -> d.bar.org/some-page

基本上类似于this,但用于 IIS。

这是我目前的尝试:

    <rule name="redirect" enabled="true">
      <match url="(.*)" />
        <conditions>
          <add input="{HTTP_HOST}" negate="true" pattern="^(.*)\.foo\.com$" />
        </conditions>
      <action type="Redirect" url="http://{C:1}.bar.org/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>

【问题讨论】:

标签: iis web-config


【解决方案1】:

啊,终于搞定了:

    <rule name="redirect" enabled="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" negate="false" pattern="^(.*)\.foo\.com" />
      </conditions>
      <action type="Redirect" url="https://{C:1}.bar.org/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>

不过,我并不完全理解这条规则:/ 例如,如果不将“negate”设置为 false,它就无法工作。

【讨论】:

    猜你喜欢
    • 2016-07-13
    • 2019-12-20
    • 2021-09-09
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2013-08-24
    相关资源
    最近更新 更多