2011-10-03 137 views
2

有一個現有的網站H * TP重定向/。舊網站已被設置爲新網站主機帳戶上的停放網域。以下是newsite主機的文件結構。 H * TP://www.newsite.co.za/ - /的public_html H * TP://www.oldsite.com/ - /public_html/oldsite.comhtaccess的從舊網站到新網站

的newsite是的一個完整的重組oldsite,所以我需要的oldsite的所有索引的網頁重定向到newsite的一些相應的頁面。我設法重定向靜態頁面,但Im在動態頁面上很難。例如:

h*tp://www.oldsite.com/The_Wine_Shop/Bales_Private_Vintners.aspx?CatID=13&PageID=175&RefPageID=169 

h*tp://www.newsite.co.za/buy-wine/buy-wine-online/ 

有跡象表明,需要根據上面的例子格式被重定向幾頁。什麼是最簡單的重定向方式。我想剛纔的所有文件重定向包括動態頁的「The_Wine_Shop」文件夾中,但我沒有任何想法如何做,在這種格式。

通過這裏的方法是我oldsite到newsite索引頁面重定向代碼。

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^oldsite\.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite\.com 
RewriteRule ^/?(.*) http://www\.newsite\.co\.za/$1 [R=permanent,L] 

回答

1

您可以添加另一個規則集來你的.htaccess:

RewriteCond %{REQUEST_URI} ^/The_Wine_Shop/ 
RewriteRule ^(.*)$ http://www.newsite.co.za/buy-wine/buy-wine-online/ [R=301,L] 

這將每一個頁面重定向與/The_Wine_Shop/開始。

如果你想檢查請求的URI,你可以像這樣的東西去查詢字符串:

RewriteCond %{REQUEST_URI} ^/The_Wine_Shop/Bales_Private_Vintners\.aspx$ 
RewriteCond %{QUERY_STRING} CatID=13 
RewriteCond %{QUERY_STRING} PageID=175 
RewriteCond %{QUERY_STRING} RefPageID=169 
RewriteRule ^(.*)$ http://www.newsite.co.za/buy-wine/buy-wine-online/ [R=301,L] 

如果你不介意的URL被寫入大寫或小寫的添加NC-Flag的條件。

你也應該在<link rel="canonical" href="http://new-and-correct-url" />標記添加到您的新網站<head>

Moreinfo上相對規範。