.htaccess - 在使用 cPanel 的 Linux 主机中从 HTTP 重定向到 HTTPS 不起作用
问题描述
我已经尝试了在不同站点找到的所有内容,但没有任何效果。
这些是我在 .htaccess 文件中尝试过的所有不同解决方案。我已经一一尝试了所有解决方案以及一些组合,但没有任何效果。
RewriteEngine On
# 1 option
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 2 option
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS_HOST} !^www.mywebsite.camp$ [NC,OR]
RewriteCond %{HTTP_HOST} !^www.mywebsite.camp$ [NC]
RewriteRule ^(.*)$ https://www.mywebsite.camp/$1 [L,R=301]
# 3 option
RewriteCond %{HTTP_HOST} ^mywebsite\\.camp [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.camp/$1 [R,L]
# 4 option
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^mywebsite\.camp [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.camp$
RewriteRule .* https://www.mywebsite.camp%{REQUEST_URI} [R=301,L]
# 5 option
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# 6 option
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#### Remove index.php ###
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
#### index.php ###
当我尝试直接从浏览器输入访问我的网站时:https://mywebsite.camp/它运行良好
我能做些什么?在此先感谢您的帮助!
解决方案
推荐阅读
- docker - 我不能在 Dockerfile 中执行 RUN cp
- python - 为什么 python 库会从桌面运行,但从 PHP 调用时却不行?
- doctrine-orm - 关联实体在测试环境中未正确加载,但在开发中工作(Symfony 5 + Doctrine 2)
- perl - 我需要用定义的(@array)和定义的(%hash)重构一段古老的 Perl 代码
- java - 按钮未出现在 GUI 上
- reactjs - 如何在上下文 Api 中更新状态?
- rstudio-server - 未找到 Rstudio 服务器摇杆图像内存限制文件
- c# - 从 Blazor 服务器下载文件,无需单独的下载页面
- python - opcua - 设置采样率后未获取队列中的所有值
- swift - 验证到期日期