首页 > 解决方案 > 在使用 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/它运行良好

我能做些什么?在此先感谢您的帮助!

标签: .htaccesshttpredirecthttps

解决方案


推荐阅读