skip to Main Content

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


  1. Try writing your RewriteRule like this:

    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.

    Login or Signup to reply.
  2. You can always use a different .htaccess rule to redirect to HTTPS. I would re-write your .htaccess to the following (hardcoding your domain):

    <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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search