网站根目录新建 .htaccess (无法创建文件点击下载 htaccess.zip 解压) RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 站点绑定多个域名,只允许www.example.com 跳转 RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteCond %{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 OnRewriteCond %{SERVER_PORT} 80 [NC,OR]RewriteCond %{HTTP_HOST} ^example.com [NC]RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] ###把网址更改为自己的### 高级用法 (可选) RewriteEngine on# 强制HTTPSRewriteCond %{HTTPS} !=on [OR]RewriteCond %{SERVER_PORT} 80# 某些页面强制RewriteCond %{REQUEST_URI} ^something_secure [OR]RewriteCond %{REQUEST_URI} ^something_else_secureRewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]# 强制HTTPRewriteCond %{HTTPS} =on [OR]RewriteCond %{SERVER_PORT} 443# 某些页面强制RewriteCond %{REQUEST_URI} ^something_public [OR]RewriteCond %{REQUEST_URI} ^something_else_publicRewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]# ThinkPHP 跳转 添加到规则后RewriteCond %{SERVER_PORT} 80RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] |
上一篇:APACHE安装SSL证书教程
下一篇:Nginx安装SSL证书