linux - 仅主页从 http 到 https 的重定向规则

标签 linux apache security

我们可以只为主页制作 https,即

example.com or http://example.com or www.example.com or http://www.example.com

其余所有页面都应以http开头。

我这样试过,但是没用

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} "^/$"
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule ^(.*) http://%{HTTP_HOST}%{REQUEST_URI}

最佳答案

没有真正测试过,但应该会变魔术

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?$ https://%{HTTP_HOST}/ [R,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule !^/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

关于linux - 仅主页从 http 到 https 的重定向规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13252172/

相关文章:

c++ - 用C++实现一棵树

linux - 是否可以专门为 NIC 运行命令 "route -n"

java - Web 应用程序中的 CSRF 保护

php - 如何阻止某些用户访问 wamp/www/myproject 文件夹的 json 文件

phpsessid - 是否值得将 session 名称更改为散列的和特定于访问者的名称

linux - 如何检查 block 是否存在于稀疏文件中(用于简单的写时复制)?

python - 尽管我在 python ctypes 中设置了信号处理程序,但它不会被调用

apache - 主启动无法进行,在保持模式直到区域联机

java - 对象反射的安全风险是什么?

php - 快速 MySQLi 安全问题