首页 > 解决方案 > 仅将 root 和 html 文件请求重定向到 https,但保持 http 请求原样

问题描述

如果用户键入 example.comhttp://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}

标签: .htaccess

解决方案


推荐阅读