将所有子域重定向到新域
Redirect all subdomains to new domain
我想使用 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>
啊,我终于成功了:
<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,它就无法工作。
我想使用 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>
啊,我终于成功了:
<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,它就无法工作。