寻找最佳实践。
我有2个域,oldsite.com
和mynewsite.com
将它们添加到我的oldsite.com
Apache2配置文件:
#homepage
Redirect 301 / https://www.mynewsite.org
#rest of pages
Redirect 301 /old/page/location1 https://www.mynewsite.org/some/new/page1
Redirect 301 /old/page/location2 https://www.mynewsite.org/another/new/page/here
我有大量的重定向要做(100 )。喜欢保持尽可能整洁。寻找最佳实践。说mynewsite.com
有一天发生变化。我希望能够在conf文件中更新一个位置。
看起来您对旧域上的Apache配置有控制权。
最好使用 RewriteMap
供成千上万的重定向。这是您可以使用它的方法:
-
在
httpd.conf
文件中添加以下行以定义RewriteMap
:RewriteMap redirMap txt://full/path/to/redirects.txt
-
以
/full/path/to/redirects.txt
的形式创建一个文本文件:/old/page/location1 /new/pag1 /old/page/location2 /new/pag2 / /
-
在您的apache config或vhost config或站点root .htaccess中添加这些行:
Options +FollowSymLinks RewriteEngine on RewriteCond ${redirMap:$0} . RewriteRule .* https://www.mynewsite.org${redirMap:$0} [L,R=301,NE]
这对于mynewsite.com
来说非常方便,因为您需要在一个规则中更改域名。