.htaccess - 无法将 http 请求重定向到 https
问题描述
您好,我想将我的 http 请求重定向到 https。我向 .htaccess 添加了一些代码,但我仍然可以使用 http 访问我的网站。出了什么问题,我该怎么办?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteOptions inherit
Header set content-Security-Policy: upgrade-insecure-requests
解决方案
通过您显示的尝试,您能否尝试遵循 htaccess rues 设置。由于您对规则使用继承选项,因此如果您想在所有 URL 中应用 https,那么最好将您的 htpps 规则放在您的 BASE(非常一级文件夹明智)htaccess 文件中,如果您愿意,我们不需要将它们放在这里仅将 https 应用于此处介绍的 URL,然后使用以下样式规则。
请确保在测试您的 URL 之前清除您的浏览器缓存。
<IfModule mod_rewrite.c>
RewriteOptions inherit
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Header set content-Security-Policy: upgrade-insecure-requests
推荐阅读
- javascript - 当组件的道具更新时动画
- ruby-on-rails - jquery 在生产中不像在开发中那样工作
- python - 如何使用正则表达式从此有效负载中提取字段?
- python - 在 folium 中显示栅格数据(不处理数据值)。
- reactjs - 收到错误说 TypeError undefined is not an object
- airflow - Airflow DAG 每秒运行一次,而不是每分钟运行一次
- javascript - JavaScript/CSS/HTML 在鼠标悬停时淡出和移动元素
- angular - 检查输入中输入的数字在数学上是否有效
- pandas - 为什么 pandas DataFrame.append() 会给出时区值错误?
- regex - Bash pgrep 正则表达式函数