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!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

force https for a given website and not all hosted accounts

Discussion in 'Security' started by trucmuche, Nov 27, 2016.

Tags:
  1. trucmuche

    trucmuche Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    80
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Hello,

    I host many websites using WHM/CPanel and for ONE of them, I would like to force my visitors to use HTTPS instead of HTTP. Of course, I have already installed a SSL certificate and I can perfectly see my website using https://subdomain.mydomain.com.

    Is there a way to force HTTPS on ONE account and not globally ?
    Is there a WHM/CPanel solution or should I use .htaccess ??

    Thank you very much for your help !

    T.
     
  2. Eminds

    Eminds Well-Known Member

    Joined:
    Nov 10, 2016
    Messages:
    211
    Likes Received:
    13
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.

    Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.


    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    
    Be sure to replace www.example.com with your actual domain name.

    To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    
    Make sure to replace example\.com with the domain name you're trying force to https. Additionally, you need to replace example.com with your actual domain name.
     
    #2 Eminds, Nov 27, 2016
    Last edited by a moderator: Nov 27, 2016
  3. trucmuche

    trucmuche Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    80
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Thanks ! So, to ensure that I understand correctly your answer (because I'm not sure to understand perfectly the difference between the two alternatives you're talking about - what's the difference ?)...

    I would like to redirect the HTTP visitors of my subdomain to HTTPS address (when they try to access my website using HTTP, switch them to HTTPS). So I have to put a .htaccess file in the /home/mydomain/subdomain.example.com/ folder and write inside :
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://subdomain.example.com/$1 [R,L]
    
    Is that right ? Or should I put this .htaccess (also ?) in /home/mydomain/public_html directory ?

    Thanks again !
     
    #3 trucmuche, Nov 27, 2016
    Last edited by a moderator: Nov 27, 2016
  4. SysSachin

    SysSachin Well-Known Member

    Joined:
    Aug 23, 2015
    Messages:
    569
    Likes Received:
    40
    Trophy Points:
    28
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Twitter:
    You will have to use following code in your /home/mydomain/public_html directory and same code in your subdomain directory (/home/mydomain/subdomain.mydomain.com/), Just change your domain name to sub-domain.

    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
     
  5. trucmuche

    trucmuche Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    80
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Thank you very much !! :)
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    I'm happy to see the provided information was helpful. Let us know if you have any additional questions.

    Thank you.
     
Loading...

Share This Page