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. 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. 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
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]
2
Answers
Try writing your
RewriteRule
like this: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 toR=301
as that will make it a permanent redirect.You can always use a different .htaccess rule to redirect to HTTPS. I would re-write your .htaccess to the following (hardcoding your domain):