Apache自动跳转到 HTTPS
网站根目录新建 .htaccess (无法创建文件点击下载 htaccess.zip 解压)
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
站点绑定多个域名,只允许www.example.com 跳转
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{HTTP_HOST} ^example.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
都跳转到https://www.example.com
RewriteEngine On RewriteCond %{SERVER_PORT} 80 [NC,OR] RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
###把网址更改为自己的###
高级用法 (可选)
RewriteEngine on # 强制HTTPS RewriteCond %{HTTPS} !=on [OR] RewriteCond %{SERVER_PORT} 80 # 某些页面强制 RewriteCond %{REQUEST_URI} ^something_secure [OR] RewriteCond %{REQUEST_URI} ^something_else_secure RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] # 强制HTTP RewriteCond %{HTTPS} =on [OR] RewriteCond %{SERVER_PORT} 443 # 某些页面强制 RewriteCond %{REQUEST_URI} ^something_public [OR] RewriteCond %{REQUEST_URI} ^something_else_public RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] # ThinkPHP 跳转 添加到规则后 RewriteCond %{SERVER_PORT} 80 RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]