一门APP开发教程

标题: Apache自动跳转到 HTTPS Apache设置http跳转https [打印本页]

作者: 希望工程boss    时间: 2020-4-24 16:23
标题: Apache自动跳转到 HTTPS Apache设置http跳转https
Apache自动跳转到 HTTPS Apache设置http跳转https

网站根目录新建 .htaccess
  1. RewriteEngine On
  2. RewriteCond %{SERVER_PORT} 80
  3. RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
复制代码


站点绑定多个域名,只允许www.example.com 跳转

  1. RewriteEngine On
  2. RewriteCond %{SERVER_PORT} 80
  3. RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
  4. RewriteCond %{HTTP_HOST} ^www.example.com [NC]
  5. RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
复制代码
******把网址更改为自己的******



高级用法 (可选)
RewriteEngine on

  1. # 强制HTTPS
  2. RewriteCond %{HTTPS} !=on [OR]
  3. RewriteCond %{SERVER_PORT} 80
  4. # 某些页面强制
  5. RewriteCond %{REQUEST_URI} ^something_secure [OR]
  6. RewriteCond %{REQUEST_URI} ^something_else_secure
  7. RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
  8. # 强制HTTP
  9. RewriteCond %{HTTPS} =on [OR]
  10. RewriteCond %{SERVER_PORT} 443
  11. # 某些页面强制
  12. RewriteCond %{REQUEST_URI} ^something_public [OR]
  13. RewriteCond %{REQUEST_URI} ^something_else_public
  14. RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
复制代码











欢迎光临 一门APP开发教程 (https://bbs.yimenapp.com/) Powered by Discuz! X3.4