我有一个子目录(http://example.com/forum
)我希望301重定向到htttp://forum.exampple.com
的新子域。如何使用Web.config和IIS重写来设置重定向,以将所有请求发送到http://example.com/forum/*
到htttp://forum.exampple.com
?谢谢!
答案 0 :(得分:4)
通过转换ssri提供的规则,规则在web.config文件中应如下所示:
<rewrite>
<rules>
<rule name="your name here" stopProcessing="true">
<match url="^forum/(.*)$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="http://forum.exampple.com/{R:1}" />
</rule>
</rules>
</rewrite>
将它放在system.webServer标记之间。
答案 1 :(得分:0)
要获得传递给子域的查询字符串,您可以尝试这样吗
RewriteRule ^ / forum /(.*)/? http://forum.exampple.com/ $ 1 [R = 301,L]
在重写规则中,如果以$结尾,则会占用整个网址(包括查询),因此请尝试将$替换为/?在没有查询的情况下获取截断的请求。
如果您确定新网址不需要任何查询字符串,可以将其更改为
RewriteRule ^ / forum /(.*)/? http://forum.exampple.com/ $ 1 /? [R = 301,L]