【问题标题】:How can I use mod_rewrite to redirect URLs from one subdomain to another? [closed]如何使用 mod_rewrite 将 URL 从一个子域重定向到另一个子域? [关闭]
【发布时间】:2012-09-07 16:50:58
【问题描述】:

我有一个测试网络服务器:abc2.example.com。我将网站:abc1.example.com 迁移到了这个测试服务器(abc2)。 abc2 上的所有链接都保持不变,并指向 abc1 的页面。当我单击 abc2 上的链接时,我希望它转到 abc2 托管页面而不是转到 abc1。如何使abc2.example.com/anypage 上的所有传出链接转到abc2.example.com/anypage 而不是转到abc1.example.com/anypage

我已经尝试使用 mod_rewrite(添加到 httpd.conf)来执行此操作:

RewriteCond %{HTTP_HOST} ^abc1\.example\.com [NC]
RewriteRule ^(.*)$ http:\/\/abc2\.example\.com/$1 [R,L]

...但这似乎不起作用

我希望保持链接不变,因为abc2.example.com 将很快接管abc1.example.com 并成为现场制作网站。

【问题讨论】:

    标签: linux apache mod-rewrite


    【解决方案1】:

    如果这是一个完美的 1:1 映射,并且两个站点之间唯一改变的是主机名,那么您不需要 mod_rewrite。一个简单的

    RedirectMatch (.*) http://abc1.example.com$1
    

    在 abc2 虚拟主机定义中就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-28
      • 1970-01-01
      • 2019-01-12
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      相关资源
      最近更新 更多