网站根目录新建 .htaccess
1 2 3 |
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L] |
301跳转
1 2 3 4 5 6 |
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L] </IfModule> |
站点绑定多个域名,只允许www.gworg.com 跳转
1 2 3 4 5 |
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,L] |
###把网址更改为自己的###
高级用法 (可选)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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 .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] |
声明: 本文由( 小天 )原创编译,转载请保留链接: Apache自动跳转到 HTTPS
------====== 本站公告 ======------
欢迎使用趣域网域名百科,我们将长期提供域名使用相关知识和投资域名的方法和技巧;并提供主机、服务器的解决问题和网站运营方法。