Regex Apache2配置重定向

Regex Apache2配置重定向,regex,apache,url-redirection,Regex,Apache,Url Redirection,寻找这方面的最佳实践 我有两个域名,oldsite.com和mynewsite.com 将这些添加到我的oldsite.comapache2配置文件中: #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/location

寻找这方面的最佳实践

我有两个域名,
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配置

最好使用它来满足您对数千个重定向的需求。以下是如何使用它:

  • 将以下行添加到您的
    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配置或vhost配置或站点root.htaccess中添加以下行:

    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteCond ${redirMap:$0} .
    RewriteRule .* https://www.mynewsite.org${redirMap:$0} [L,R=301,NE]
    

  • 这对于
    mynewsite.com
    更改某一天的要求非常方便,因为您只需要在一个规则中更改域名

    这是有效的。谢谢还有一个问题,我发现我可以使用:
    RedirectMatch 301^(.*)$https://www.mynewsite.org
    但当我使用此选项时,我设置的所有其他重定向都会被发送到根目录(主页)。我只是想知道是否有办法做到这一点,并且手动重定向也能起作用。我建议将所有重定向保存在
    redirect.txt
    文件中。但是,如果存在保留其他
    301
    重定向的用例,则在该规则之后保留它们。而且一定要保持
    RedirectMatch 301^(.*)$https://www.mynewsite.org
    在最后,因为它将匹配所有内容。完美,我想确认这一点。再次感谢你所做的一切。