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.

SOLVED HTTPS Redirection For All VirtualHosts

Discussion in 'EasyApache' started by THawke, Jun 16, 2017.

  1. THawke

    THawke Member

    Joined:
    Jun 16, 2017
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Looking for a way to redirect http traffic to https across all VirtualHosts by default. To try to accomplish this I've copied vhost.default to vhost.local in /var/cpanel/tempaltes/apache2_4 and have added various methods for redirection to the bottom of the vhost template including:
    Code:
    Redirect / https://[% wildcard_safe(vhost.servername) %]/
    and
    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} 
    I have tried a few different Rewrite rules to try to get it to work. However, whatever I use seems to redirect to an https url okay, but is creating a redirect loop. It appears to be generating the correct configuration in httpd.conf according to the documentation I've read, so I'm not sure where the redirect loop is coming from. It's a freshly spun up VM, everything is default other than a few imported cpanel accounts for testing and the vhost redirection snippet I'm trying to inject via the template.
     
  2. THawke

    THawke Member

    Joined:
    Jun 16, 2017
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Forgot to mention that I'm using the LetsEncrypt autossl provider, I'm not sure that would affect anything. Using apache and cpanel config defaults and going to an accounts cpanel and adding a redirect from / to https://domain redirecting with and without www. and with or without wild card redirect is also creating the redirect loop.
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    36,999
    Likes Received:
    1,275
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
  4. THawke

    THawke Member

    Joined:
    Jun 16, 2017
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Putting
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTPHOST}%{REQUESTURI}
    into a file at the specified path is working as expected. Thanks.
     
  5. THawke

    THawke Member

    Joined:
    Jun 16, 2017
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Alright, never mind, it's still not functioning properly. Without the configuration I can request a test domain with a "Hello World" index page with CURL from both http and https. When I add this configuration
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTPHOST}%{REQUESTURI}
    in /etc/apache2/conf.d/userdata/std/2_4/redirect.conf, I can request the file via curl from https directly okay, but when I request the http, I get curl: (47) Maximum (50) redirects followed. Fresh vps and cpanel, only added a test account. OS CENTOS 6.9 x86_64 cPanel & WHM 64.0
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    36,999
    Likes Received:
    1,275
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you open a support ticket using the link in my signature so we can take a closer look? You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
  7. THawke

    THawke Member

    Joined:
    Jun 16, 2017
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Support request ID: 8626835
     
  8. THawke

    THawke Member

    Joined:
    Jun 16, 2017
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Putting:
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    In a .conf file under /etc/apache2/conf.d/userdata works well. There was also an issue with CloudFlare proxy that was not requesting via http so https requests would come back with the redirect to http causing the loop.
     
    cPanelMichael likes this.
Loading...

Share This Page