在.htaccess重定向多个域名一个多个、重定向、域名、htaccess

2023-09-02 10:03:59 作者:酸楚沾满心房

我想补充一些code到我的.htaccess重定向到几个不同的领域,以单个域。我见过code,将一个域做到这一点,如:

I would like to add some code to my .htaccess to redirect several different domains to a single domain. I have seen code that will do this for one domain such as:

RewriteCond %{HTTP_HOST} ^www.example.net  
RewriteRule (.*) http://www.example.com/$1 [R=permanent,QSA,L]

但是,什么是有重定向到一个域多个域的最佳方法?

But what is the best approach to have multiple domains redirected to a single domain?

推荐答案

只有重定向如果域的没有的要重定向到一个:

Only redirect if the domain is not the one you want to redirect to:

RewriteCond %{HTTP_HOST} !(^www.example.com$)  
RewriteRule (.*) http://www.example.com/$1 [R=permanent,QSA,L]
 
精彩推荐