我想使用web.config
规则将所有流量重定向(301)到一个新域,但是该站点还在处理越来越多的子域列表,这些子域也需要重定向。
如何为以下内容编写规则?
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>
答案 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,它就无法工作。