使用Apache将旧域上的旧路径重定向到新域上的新路径

使用Apache将旧域上的旧路径重定向到新域上的新路径,apache,.htaccess,redirect,Apache,.htaccess,Redirect,假设我有3个域: oldsite.com anotheroldsite.com 和 新闻网站 我需要将旧域中的特定URL重定向到新域中的特定路径。例如: oldsite.com/potato=>www.newsite.com/how-about-a/potato www.oldsite.com/potato=>www.newsite.com/how-about-a/potato 和 anotheroldsite.com/products=>www.newsite.com/sub-dir-befo

假设我有3个域:

oldsite.com
anotheroldsite.com

新闻网站

我需要将旧域中的特定URL重定向到新域中的特定路径。例如:

oldsite.com/potato=>www.newsite.com/how-about-a/potato
www.oldsite.com/potato=>www.newsite.com/how-about-a/potato
和 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

在过去的一个小时里,我花了大部分时间来寻找实现这一点的最佳方法,但我似乎找不到任何关于旧域和具有完全不同路径的新域的示例


重要提示:所有域名A-records都指向newsite.com的IP

您必须一次创建一个URL,这取决于您可以从旧URL映射到新URL的模式

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]
等等