简体   繁体   English

将所有流量从一个域重定向到另一个域

[英]Redirect all traffic from one domain to another

What I am trying to do is automatically redirect the domain for one of my sites 我想要做的是自动重定向我的一个网站的域名

www.domain1.com to www.domain2.co.uk www.domain1.comwww.domain2.co.uk

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain1.com\. [NC]
RewriteRule (.*) http://%www.domain2.com\%{REQUEST_URI} [R=301,NC,L]

I have looked over the site for the answer and the above is my code that I edited from another answer, but it doesn't work. 我查看了网站上的答案,上面是我从其他答案编辑的代码,但它不起作用。

I would like it in a .htaccess file - is this the best way of doing it? 我想在.htaccess文件中 - 这是最好的方法吗?

Thanks 谢谢

To redirect from www.domain1.com to www.domain2.co.uk , you may try this: 要从www.domain1.com重定向到www.domain2.co.uk ,您可以尝试这样做:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^(.*)$ http://www.domain2.co.uk/$1 [R=301,NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM