.htaccess实现强制https访问,将http 301重定向到https 不指定

Heck post in Web开发 2016/11/13 16:15 评论(0) 阅读(368) | |
最近有个客户要http的301跳转到SSL的https网址,实现如下:
RewriteCond %{ENV:HTTPS} !^on$
RewriteCond %{HTTP:X-Sakura-Forwarded-For} ^$
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

或者
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.hecks.tk/$1 [R=301,L]

或者
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]


#301到www
RewriteCond %{HTTP_HOST} ^hecks.tk$ [NC]
RewriteRule ^(.*)$ https://www.hecks.tk/$1 [L,R=301]

#只跳http的80端口,https是443
RewriteCond %{HTTP_HOST} ^(hecks.tk)(:80)?
RewriteRule ^(.*) https://www.hecks.tk/$1 [R=301,L]

来源:Heck's Blog
地址:http://www.hecks.tk/post/443/
转载时须以链接形式注明作者和原始出处及本声明,否则将追究法律责任,谢谢配合!