【问题标题】:Apache redirect from one subdomain to anotherApache 从一个子域重定向到另一个子域
【发布时间】:2019-01-12 01:48:24
【问题描述】:

有谁知道从 a.example.com 永久重定向到 b.example.com 的方法?我还有其他需要保持原样的子域。所以:

first.example.com -> second.example.com
third.example.com is fine
fourth.example.com is fine 

我想在 <VirtualHost> 块而不是 .htaccess 中执行此操作,以避免再次重新部署。

任何想法都将不胜感激,谢谢

【问题讨论】:

    标签: apache .htaccess mod-rewrite virtualhost


    【解决方案1】:

    将以下RewriteRule 添加到您的VirtualHost

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^first.example.com$
    RewriteRule ^ http://second.example.com [R=301,L]
    

    如果您想将first.example.com/some/url 重定向到second.example.com/some/url

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^first.example.com$
    RewriteRule /(.*) http://second.example.com/$1 [R=301,L]
    

    建议您在测试规则时使用[R=302],以避免浏览器缓存 301 出现问题。

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 2023-02-14
      • 2013-10-19
      相关资源
      最近更新 更多