2014-07-21 122 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] 

相关问题