htaccess 如何将 www.domain.com 和 domain.com 重定向到 www.realdomain.com
我为一堆域设置了 htaccess 重定向,使其全部指向我的主域 - 但是它们仅将 domain.com
重定向到 www.realdomain.com
,如果您点击 www.domain.com
重定向不会发生。
这是我所拥有的(每个域都会复制 rewritecond 和 rewriterules):
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.realdomain.com/$1 [R=301,L]
我对正则表达式的了解有点有限,但我认为它会查找以 domain.com
开头的地址,因此这是有道理的与 www.domain.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.
Here's what I have (rewritecond and rewriterules are replicated for each domain):
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
.
Is there a way I can make that regexp match both of them without having to double the number of rules I already have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以选择将其更改为
rewritecond %{http_host} ^(www\.)?domain.com [nc]
来匹配www.
You can have it optionally also match
www.
by changing the line torewritecond %{http_host} ^(www\.)?domain.com [nc]