Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Redirecting http to https not working as expected

Discussion in 'Bind/DNS/Nameserver' started by Angel Castro, Feb 22, 2019.

Tags:
  1. Angel Castro

    Angel Castro Active Member

    Joined:
    Jul 16, 2018
    Messages:
    36
    Likes Received:
    3
    Trophy Points:
    8
    Location:
    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.
     
    #1 Angel Castro, Feb 22, 2019
    Last edited by a moderator: Mar 14, 2019
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,555
    Likes Received:
    2,182
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Raw333 likes this.
  3. Angel Castro

    Angel Castro Active Member

    Joined:
    Jul 16, 2018
    Messages:
    36
    Likes Received:
    3
    Trophy Points:
    8
    Location:
    Aguascalientes, México
    cPanel Access Level:
    Root Administrator
    Hi @cPanelMichael, didn't work, doesn't redirect http to https.

    Thanks anyway.
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,555
    Likes Received:
    2,182
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hi @Angel Castro,

    Feel free to open a support ticket if you'd like us to access your system to see if there's anything obvious that's preventing the redirect from working.

    Thanks!
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice