通用 htaccess 将 www 重定向到非 www [英] Generic htaccess redirect www to non-www
本文介绍了通用 htaccess 将 www 重定向到非 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 www.example.com
重定向到 example.com
.以下 htaccess 代码实现了这一点:
I would like to redirect www.example.com
to example.com
. The following htaccess code makes this happen:
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
但是,有没有一种方法可以在不对域名进行硬编码的情况下以通用方式执行此操作?
But, is there a way to do this in a generic fashion without hardcoding the domain name?
推荐答案
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
与 Michael 的 相同,只是这个有效:P
Same as Michael's except this one works :P
这篇关于通用 htaccess 将 www 重定向到非 www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文