在Linux中使用cPanel托管从HTTP重定向到HTTPS不起作用

时间:2020-07-05 14:39:17

标签: .htaccess http redirect 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/,效果很好

我该怎么办? 预先感谢您的帮助!

0 个答案:

没有答案