How to redirect one domain to another

两盒软妹~` 提交于 2019-12-12 20:19:04

问题


I have two domains:

www.example1.com/ --> IP=1.2.3.4
www.example2.com/ --> IP=1.2.3.4 (same IP for both domains)

I want all requests that go to www.example2.com/* to access the requested page. I want all requests that go to www.example1.com/* to redirect to www.example2.com/*. How would I do this in apache? As now I am currently doing this in javascript.


回答1:


put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com [NC]
RewriteRule ^ http://www.example2.com%{REQUEST_URI} [NE,R=301,L]


来源:https://stackoverflow.com/questions/24619550/how-to-redirect-one-domain-to-another

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