将所有子域重定向到新域

时间:2019-02-01 15:34:46

标签: iis web-config

我想使用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>

1 个答案:

答案 0 :(得分:0)

啊,我终于开始工作了:

    <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,它就无法工作。

相关问题