Apache2 conf redirect



寻找最佳实践。

我有2个域,oldsite.commynewsite.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 供成千上万的重定向。这是您可以使用它的方法:

  1. httpd.conf文件中添加以下行以定义RewriteMap

    RewriteMap redirMap txt://full/path/to/redirects.txt
    
  2. /full/path/to/redirects.txt的形式创建一个文本文件:

    /old/page/location1 /new/pag1
    /old/page/location2 /new/pag2
    / /
    
  3. 在您的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来说非常方便,因为您需要在一个规则中更改域名

最新更新