2010-11-17 24 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

相關問題