[英]cpanel .htaccess is not redirecting to HTTPS
I'm missing something simple I'm sure, some insight would be very helpful. 我敢肯定,我缺少一些简单的东西,一些见解会很有帮助。 I am working on setting up web site on a vps using cpanel.
我正在使用cpanel在vps上建立网站。 I'm trying to get it to always redirect to https instead having both available, I can do this without cpanel, but seem to be stumped when cpanel gets involved.
我正在尝试使其始终重定向到https而不是同时可用,我可以在不使用cpanel的情况下执行此操作,但是当cpanel参与进来时似乎很困惑。 I saw this, but it was zero help https://www.namecheap.com/support/knowledgebase/article.aspx/9770/38/how-to-force-https-using-htaccess-file-in-cpanel
我看到了这个,但对您来说却是零帮助https://www.namecheap.com/support/knowledgebase/article.aspx/9770/38/how-to-force-https-using-htaccess-file-in-cpanel
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Try writing your RewriteRule
like this: 尝试像这样编写您的
RewriteRule
:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L,NE]
Make sure you clear your cache before you test this. 在测试之前,请确保清除缓存。 I've set the flag to
R
, but if you're happy with the redirection then change it to R=301
as that will make it a permanent redirect. 我将标志设置为
R
,但是如果您对重定向感到满意,则将其更改为R=301
因为这将使它成为永久重定向。
You can always use a different .htaccess rule to redirect to HTTPS. 您始终可以使用其他.htaccess规则来重定向到HTTPS。 I would re-write your .htaccess to the following (hardcoding your domain):
我会将您的.htaccess重写为以下内容(对您的域进行硬编码):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.