.htaccess - 仅将 root 和 html 文件请求重定向到 https,但保持 http 请求原样
问题描述
如果用户键入
example.com
,http://example.com
或者http://example.com/x.html
它应该总是重定向到 https
但我想保持通过 http 访问热链接文件(我的一些旧软件已经硬编码了指向 Web 资源的 http 路径,并且在不重定向的情况下仍然可以工作)
如何修改 .htaccess?我拼凑了这个,我认为这意味着“如果 https 已关闭并且它是 .html 页面或根目录,则打开以 https 为前缀的页面”,但它完全破坏了网站。
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME}\.html -f [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
解决方案
推荐阅读
- c++ - pcl::io::loadPCDFile("2.pcd", *cloud); 错误
- xml - 用于下载 XML 并使用 XPath 生成新 XML 的脚本
- c# - 测量每个实体框架查询的时间
- javascript - 在 Javascript 中继承静态属性
- selenium - 如何使用 Selenium 和 Python 单击 iframe 内的按钮
- pdf - 遍历整个PDF并将蓝色更改为黑色并删除下划线(但仅限于包含“http//”和“https//”的文本)+ iText
- sql-server - 如何在swift中执行插入、更新和删除(sql server)查询
- php - 关系的访问关系
- linux - 在 RedHat 7.7 中使用 grep
- c# - 使用 Pomelo EF net-core 3.0 创建迁移时出错,数据库:MySql