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.

Apache redirection to SSL

Discussion in 'EasyApache' started by jakeyg, Sep 5, 2014.

  1. jakeyg

    jakeyg Registered

    Joined:
    Sep 5, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi all

    Im having trouble with redirection in Apache using WHM and CPanel. I have a main site

    domain.com.au

    I would like to ensure that all pages redirect to the cannonical a

    https://www.domain.com.au

    I have been trying to use WHM>>>service configuration>>>apache configuration>>>include editor>>>Post virtual host include

    Code:
    <VirtualHost *:80>
    RedirectPermanent / https://www.domain.com.au
    </VirtualHost>
    
    All WHM/CPanel/Webmail/FTP are set to SSL and work fine. I just cant get this to work. All the documentation says that i should use redirect as opposed to mod rewrite and i would like to as it seems cleaner. The above doesnt seem to do anything. I have also used the example shown here https://wiki.apache.org/httpd/RedirectSSL

    Code:
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName www.domain.com
    Redirect permanent / https://www.domain.com/
    </VirtualHost>
    
    <VirtualHost _default_:443>
    ServerName domain.com
    DocumentRoot /usr/local/apache2/htdocs/domain.com/
    SSLEngine On
    # etc...
    </VirtualHost>
    Can anyone point me in the right direction?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

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

    Could you elaborate on what documentation you are referring to? You can use Mod_Rewrite rules in a .htaccess file or the "Redirects" option in cPanel if you want to redirect a website. If you do prefer to edit the VirtualHost, then you can follow the instructions in the following document:

    Modify Virtualhost Containers With Include Files

    Thank you.
     
  3. avonni

    avonni Member

    Joined:
    Sep 6, 2014
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Add this to your .htaccess file:

    Code:
    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
     
  4. jakeyg

    jakeyg Registered

    Joined:
    Sep 5, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks for the responses.

    This is where i found the documentation
    https://wiki.apache.org/httpd/RedirectSSL

    as you can see at the bottom of the page
    "While the <VirtualHost> solution is recommended because it is simpler and safer"
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    The document I provided will help you to modify the VirtualHost for an account, however the .htaccess rules are more commonly used.

    Thank you.
     
Loading...

Share This Page