[英]Redirect all subdomains and www to non-www
I would like to redirect all subdomains and www to my main “non-www” domain.我想将所有子域和 www 重定向到我的主要“非 www”域。
So:所以:
www.example.com AND sub.example.com AND www.sub.example.com www.example.com AND sub.example.com AND www.sub.example.com
Should all become:都应该变成:
example.com例子.com
How could I do this using mod_rewrite
?我怎么能用mod_rewrite
做到这一点?
Thanks谢谢
This suggests the following redirects www.example.com
to example.com
:这表明以下重定向www.example.com
到example.com
:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
As such, you could use the following to redirects anything that ends with .example.com
to example.com
:因此,您可以使用以下内容将任何以.example.com
结尾的内容重定向到example.com
:
RewriteCond %{HTTP_HOST} \.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
The following is a more generic solution (but it doesn't work for domains that are part of multi-level TLDs, such as www.theregister.co.uk
):以下是更通用的解决方案(但它不适用于属于多级 TLD 的域,例如www.theregister.co.uk
):
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.