apache - 重定向到 https 条件
问题描述
如果没有“mob”后缀,我想将我的用户重定向到 https。
例子:
如果 url = http://example.com/(anything)/mob则不要重定向到 https
如果 url = http://example.com/(anything) 重定向到 https
如果 url = http://example.com 重定向到 https
我尝试了以下代码但没有用。
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/(.*)/mob$
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
解决方案
THE_REQUEST
用变量试试这个规则:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !/mob[/?\s] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
确保在新浏览器中测试或清除浏览器缓存以避免旧缓存。
建议您将此规则作为您的首要规则。
推荐阅读
- gcc - 确定 ELF 二进制文件是否使用优化构建
- php - 运行 PHPUnit 时出现“找不到驱动程序”错误消息
- python - 将 Python 3.x 连接到 Oracle DB
- node.js - 为什么“npm 安装
" 继续重建其他不相关的模块? - r - 将变量名存储为对应的列值
- javascript - 在 get() 中返回另一个函数,为什么不能只调用它而不是添加 '()'
- postgis - 如何在postgis中将纬度/经度解析为多边形
- kubernetes - Kubernetes - 如何从 pod 检查由 --cluster-domain 设置的当前域?
- bash - Docker 容器启动命令未获取 .bashrc 变量
- sql-server - 创建触发器时出现错误,即接近尾端的语法不正确