The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

http to https

Discussion in 'General Discussion' started by arjanvr, Dec 23, 2014.

  1. arjanvr

    arjanvr Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    58
    Likes Received:
    1
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Hello,

    We just had a new wildcard installed for one of the domains on the server. On one of the subdomains it automaticlly transfers when you go to http it goes to https as it should. On the others it does not. Is there a way to set this for this domain and all subdomains in one setting change? But also, if https does not exist it goes does not create a failure somehow?

    Also, when i want port 2087, 2083 and 2096 secured with a certificate as 2086, 2082 and 2075 now redirect me to the secured ones (or should be), can i buy any ssl certificate to secure these all in one go or do i need wildcard or mulitple for this?
     
    #1 arjanvr, Dec 23, 2014
    Last edited: Dec 23, 2014
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,776
    Likes Received:
    663
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    1. You can try using the following rule in your .htaccess file within the public_html directory:

    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    However, you will need to ensure a SSL certificate is already installed for the domain name.

    2. You can purchase a certificate for the hostname of the server and install it via:

    "WHM Home » Service Configuration » Manage Service SSL Certificates"

    Thank you.
     
  3. MaxFein

    MaxFein Member

    Joined:
    Jul 29, 2015
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Portland, Oregon, USA, Earth
    cPanel Access Level:
    Root Administrator
    Love it! I can offer some possible *improvements* =)

    Code:
    RewriteCond %{HTTPS} !=on
    
    Yes, yes, I know... HTTPS is either on or off... yet in this case since we are most interested in forcing all to https I feel we should look for anything that is not explicitly 'on' - this is more along the lines of personal flavor though, unless someone knows more about how the logic works here =)

    Code:
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
    This is the big one! Since we are using server variables here we do not need to spend the overhead for a value capture () and we don't need to use the expensive .* wildcard match since we want this to match all requests and we know for certain that all lines begin from a void... =)

    Code:
    [R=301,L]
    Also, its likely that many folks will be wanting to set a 301 redirect rather than default 302 and unless one knows better I'm assuming that its also likely a good idea to set L =)

    So... all together now:

    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    Cheers, Max
     
    PLRKing likes this.
Loading...

Share This Page