2016-11-26 106 views
1

我已经看过很多关于重写的文章,但是我遇到了问题。使用SSL将www重定向到非www

example.com =>的https:// example.com(OK)
www.example.com =>的https:// example.com(OK)
HTTPS:// example.com => HTTPS :// example.com(OK)
https://开头www.example.com => https://开头example.com(FAIL)

他试了好几种论坛解决方案,但我有同样的问题。现在我的htaccess的是:

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.[^.]+)$ [NC] 
RewriteRule^https://%1%{REQUEST_URI} [L,R=301,NE] 
</IfModule> 

回答

0

您可以使用:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] 
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R=301] 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 
</IfModule> 

在你的代码,第二次测试不与HTTP进行,%1不是正确的。