的.htaccess重定向到WWW非www使用SSL / HTTPS [英] .htaccess redirect www to non-www with SSL/HTTPS
问题描述
我已经有了下一个.htaccess文件操作的几个领域,通过SSL每个保护。我需要强制HTTPS上的每个域同时确保WWW的重定向到非www的。在这里,我使用的是什么不工作是:
I've got several domains operating under a single .htaccess file, each secured via SSL. I need to force https on every domain while also ensuring www's redirect to non-www's. Here's what I'm using which doesn't work:
RewriteCond %{HTTP_HOST} ^www.%{HTTP_HOST}
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
例如:
https://www.strategice.com
应该重定向到...
should redirect to...
https://strategice.com
在此先感谢!
Thanks in advance!
推荐答案
您的条件永远是真实的,因为它像若(a == A + B)。
Your condition will never be true, because its like "if (a == a + b)".
我会尝试以下方法:
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]
这将捕获google.com,从www.google.com到1%,其余的在$ 1,之后结合2,当HTTP_HOST以www开头(带或不带HTTPS)。
This will capture "google.com" from "www.google.com" into %1, the rest in $1 and after that combining the 2, when HTTP_HOST starts with www (with or without https).
这篇关于的.htaccess重定向到WWW非www使用SSL / HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!