Redirecting http to https not working as expected

Angel Castro

Active Member
Jul 16, 2018
40
4
8
Aguascalientes, México
cPanel Access Level
Root Administrator
Hi!

I have an SSL certificate in a domain and I want when someone enters my domain as:

Code:
example.com
www.example.com
http://example.com
http://www.example.com
With some of these forms redirect to
Code:
https://example.com
In the .htaccess I have this:

Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But it does not work for me, I don't know if I'm forgetting something.
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,215
363
Hello @Angel Castro,

You could try using the following entry in the .htaccess file:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond ${HTTP_HOST} ^domain\.com [NC,OR]
    RewriteCond ${HTTP_HOST} ^www\.domain\.com [NC]
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
You'd have to replace "domain" with your actual domain name. Let me know if this helps.

Thank you.
 
  • Like
Reactions: Raw333