购买SSL域名证书之后,对于apache服务器,可以修改.htaccess配置文件,强制跳转到https
有以下几种配置方法:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
或者这样,用301跳转,保持搜索引擎权重
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
或者这样
RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
如果是在子目录,可以用这样的方法:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} subfolder RewriteRule ^(.*)$ https://www.domain.com/subfolder [R,L]
原创文章,转载请注明:转载自Web开发笔记 | htaccess强制HTTP重定向为HTTPS
本文链接地址:https://www.magentonotes.com/htaccess-http-https.html
Comments on this entry are closed.