HTTPS Redirection For All VirtualHosts
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:
and
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.
Redirect / https://[% wildcard_safe(vhost.servername) %]/and
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.
-
Hello, Rather than using a custom template, you can add the custom redirect rules using the "Apply to all virtual hosts on the system" instructions at: Modify Apache Virtual Hosts with Include Files - EasyApache 4 - cPanel Documentation Thank you. 0 -
Putting RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTPHOST}%{REQUESTURI}
into a file at the specified path is working as expected. Thanks.0 -
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 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.00 -
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. 0 -
Support request ID: 8626835 0 -
Putting: 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.0
Please sign in to leave a comment.
Comments
7 comments