2014-07-21 124 views
1

一個新的領域可以說我有3個領域:的老域名重定向舊路徑到一個新的路徑與Apache

oldsite.com
anotheroldsite.com

newsite.com

我需要將舊域中的特定URL重定向到新域中的特定路徑。如:

oldsite.com/potato => www.newsite.com/how-about-a/potato
www.oldsite.com/potato => www.newsite.com/how-about-a/馬鈴薯
和 anotheroldsite.com/products => www.newsite.com/sub-dir-before/products www.anotheroldsite.com/products => www.newsite.com/sub-dir-before/products

最後,我需要所有不匹配的請求嘗試www.newsite.com/$1

我已經花了最後一小時的更好的一部分尋找最好的方法來做到這一點,但我似乎無法F可以查看任何使用完全不同路徑查看舊域和新域的示例。

重要:所有域名A記錄指向的IP爲newsite.com

回答

1

你必須在同一時間做這一個網址,取決於你能得到什麼模式了多少舊的網址映射到新的網址。

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^(oldsite\.com|anotheroldsite\.com)$ [NC] 
RewriteRule ^potato$ http://newsite.com/how-about-a/potato [L,R=301] 

RewriteCond %{HTTP_HOST} ^(oldsite\.com|anotheroldsite\.com)$ [NC] 
RewriteRule ^products$ http://newsite.com/sub-dir-before/products [L,R=301] 


... 

RewriteCond %{HTTP_HOST} ^(oldsite\.com|anotheroldsite\.com)$ [NC] 
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301] 

相關問題