重定向一个领域到另一个在同一个IP重定向、领域、在同一个、IP

2023-09-02 01:10:36 作者:我又没失忆怎能说忘就忘丶

我有两个网站,可以给他们打电话example.com和example2.com。

I've got two sites, lets call them example.com and example2.com.

用于该网站只能通过example.com访问,但我们的客户希望改变,因此,他们注册example2.com他们的名字。现在example.com且example2.com现在指向同一个网站。

The website used to only be accessible via example.com but our client wanted to change their name so they registered example2.com. Now example.com and example2.com are now pointing to the same website.

我需要一个htaccess规则,将引导所有流量通过旧域example.com访问该网站,301重定向到新的域名example2.com。

I need an htaccess rule that will direct all traffic accessing the site via the old domain example.com and 301 redirect it to the new domain example2.com.

我知道这是怎么回事包括至少一个REWRITE_COND,但我不知道是什么语法我需要的。

I know it's going involve at least one REWRITE_COND but I don't know what syntax I need.

推荐答案

没关系,我理解了它。这里是我的解决方案:

Nevermind, I figured it out. Here's my solution:

# Redirect Traffic from old domain
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule (.*) http://www.example2.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example2.com/$1 [R=301,L]