Redirect One domain to another on the same IP

╄→尐↘猪︶ㄣ 提交于 2019-12-24 23:29:55

问题


I've got two sites, lets call them example.com and 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.

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.

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


回答1:


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]


来源:https://stackoverflow.com/questions/4830898/redirect-one-domain-to-another-on-the-same-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!