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.

Redirect http to https in WHM

Discussion in 'General Discussion' started by Edubec, Jun 2, 2015.

  1. Edubec

    Edubec Registered

    Joined:
    Feb 28, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi :)

    I have a VPS with several websites, and in one of them, I want to redirect from http to https.

    Based on the Apache documentation I can do with this:
    Code:
    <VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/
    </VirtualHost >
    
    I understand that the best way to do this in the WHM is:
    Home> Service Configuration> Apache Configuration> Include Editor

    And here is where I have a couple of questions:

    1) Should I put the above code in: Pre Virtual Host include o Post Virtual Host include?

    2) If in the future I would like to edit or delete the added code: Can I do it in the WHM? Or should I edit / delete the file included via SSH?

    Thanks for the help friends and apologize if my English is faulty.

    Eduardo
     
    #1 Edubec, Jun 2, 2015
    Last edited by a moderator: Jun 7, 2016
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    You can actually add the following entry to the .htaccess file within the account's home directory:

    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} !=443
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
    RewriteRule ^$ https://www.example.com/%{REQUEST_URI} [R,L]
    This is easier for the end-user to modify should they decide to change this behavior in the future.

    Thank you.
     
  3. Edubec

    Edubec Registered

    Joined:
    Feb 28, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks Michael !
     
  4. neilt17

    neilt17 Registered

    Joined:
    Jun 7, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    cPanel Access Level:
    Website Owner
    Shouldn't that last line be:
    Code:
    RewriteRule .* https://www.example.com/%{REQUEST_URI} [R,L]
    Rather than:
    Code:
    RewriteRule ^$ https://www.example.com/%{REQUEST_URI} [R,L]
    which will only redirect the home page but no other pages at www.example.com.
     
    #4 neilt17, Jun 7, 2016
    Last edited by a moderator: Jun 7, 2016
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page