[英]htaccess how to redirect both www.domain.com AND domain.com to www.realdomain.com
I have an htaccess redirect set up for a bunch of domains to all point towards my main domain - however they only redirect domain.com
to www.realdomain.com
, if you hit www.domain.com
the redirect doesn't take place. 我为一堆域名设置了htaccess重定向,所有域名都指向我的主域-但是,它们仅将domain.com
重定向到www.realdomain.com
,如果您单击www.domain.com
,则不会进行重定向。
Here's what I have (rewritecond and rewriterules are replicated for each domain): 这就是我所拥有的(rewritecond和rewriterules为每个域复制):
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.realdomain.com/$1 [R=301,L]
My knowledge of regexp is a bit limited but I gather that it looks for an address BEGINNING with domain.com
, so it makes sense it wouldn't match www.domain.com
. 我对regexp的了解有点有限,但我发现它正在寻找一个与domain.com
的地址,因此它与www.domain.com
不匹配是有道理的。
Is there a way I can make that regexp match both of them without having to double the number of rules I already have? 有没有一种方法可以使该regexp与它们两者匹配而不必使我已经拥有的规则数增加一倍?
You can have it optionally also match www.
您可以选择使其也匹配www.
by changing the line to rewritecond %{http_host} ^(www\\.)?domain.com [nc]
通过将行更改为rewritecond %{http_host} ^(www\\.)?domain.com [nc]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.