Skip to main content

http to https

Comments

2 comments

  • cPanelMichael
    Hello :) 1. You can try using the following rule in your .htaccess file within the public_html directory:
    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.
    0
  • MaxFein
    try using the following rule in your .htaccess file within the public_html directory:
    RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    Love it! I can offer some possible *improvements* =)
    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 =)
    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... =)
    [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:
    RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    Cheers, Max
    0

Please sign in to leave a comment.