重定向一个领域到另一个在同一个IP [英] Redirect One domain to another on the same IP

查看:199
本文介绍了重定向一个领域到另一个在同一个IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个网站,可以给他们打电话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]

这篇关于重定向一个领域到另一个在同一个IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆