redirecting several domains to one in .htaccess

2019-07-25 18:01发布

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?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-25 18:47

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]
查看更多
登录 后发表回答