2010-11-17 123 views
1

我有一个子目录(http://example.com/forum)我想301-重定向到htttp://forum.exampple.com的新子域。如何使用Web.config和IIS重写来设置重定向以将所有请求发送到http://example.com/forum/*htttp://forum.exampple.com?谢谢!使用Web.Config将目录重定向到子域

回答

3

通过转换由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标记之间。

+0

这工作,但由于某种原因它通过查询字符串的子域 - 什么办法可以从这样阻止它? – MarathonStudios 2010-11-17 19:48:48

+0

@MarathonStudios 我相信删除{R:1}会删除相对路径。 所以改变: <动作类型= “重定向” redirectType = “常驻” URL = “http://forum.exampple.com/{R:1}”/> 到 <动作类型=“重定向“redirectType =”永久“url =”http://forum.exampple.com/“/> – 2012-09-19 07:50:06

0

要获得查询字符串的乘坐传递给子域,你可以尝试这样的

重写规则^ /论坛/(.*)/? http://forum.exampple.com/ $ 1 [R = 301,L]

在重写规则中,如果以$结尾,它会占用整个url(包括查询),因此请尝试将$替换为/?在没有查询的情况下获取截断的请求。

如果你确定你的新网址不需要你可以把它改成

重写规则^ /论坛/(.*)/任何查询字符串? http://forum.exampple.com/ $ 1 /? [R = 301,L]

+0

@MarathonStudios:复制ssri提供的规则并将其粘贴到IIS URL重写模块中的”导入规则“功能中以获取正确的XML格式。 – jman 2010-11-19 09:30:28

+0

@nctml:我还没有学会使用XML重定向。你能否给我提供一些链接供我学习。 – ssri 2010-11-19 10:58:28

相关问题