HTTP to HTTPS redirects

HTTP to HTTPS redirects

10 posts / 0 new
Last post
johne's picture
johne
Points: 7
HTTP to HTTPS redirects

I want to redirect all HTTP traffic to HTTPS on my site hosted on the Acquia network. Every reference to this on the internet says to put this in your htaccess file:

RewriteCond %{HTTPS} =off [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

What setup on Acquia is causing this?

Status: 
Unresolved
johne's picture
johne
Points: 7

OK, after some digging I found that requests from the load balancer always come to the Acquia severs over HTTP so the HTTPS variable is set to off at the point at which htaccess is executed. The Server variable HTTP_X_FORWARDED_PROTO is set to https if coming from https.

So the following code works in htaccess for both Acquia and normal setups:

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
albert.martin's picture
Albert Martin
Points: 32

Thanks for responding back with the code snippet for others that may be trying to accomplish the same thing! The reason the first snippet doesn't work for redirects is because your site sits behind Varnish on Acquia Cloud. I am going to check with our documentation team and see about getting this information a bit easier to find in our documentation.

Status Change: 
Resolved
crowe@isovera.com's picture
crowe
Points: 0

UPDATE: False alarm. I was editing the wrong .htaccess file.

Got it working

https://docs.acquia.com/cloud/configure/https seems like the place to document this.

johne's picture
johne
Points: 7

I can;t see any problem with your htaccess - though for this level of control you might want to consider doing the redirection in PHP - perhaps using the securepages module?

webmaster345's picture
webmaster
Points: 0

THANK YOU FOR THIS!

And Acquia team, please please please add this to https://docs.acquia.com/cloud/configure/https as suggested. I just wasted half a day on this until I came here.

sstedman@commonsensemedia.org's picture
sstedman
Points: 0

THANK YOU JOHNE!

This is the only place I have found anywhere on the web that describes using {HTTP:X-Forwarded-Proto} to achieve an .htaccess redirect on acquia. I will triple vote that you PLEASE add this to your docs at https://docs.acquia.com/cloud/configure/https!

albert.martin's picture
Albert Martin
Points: 32

Thanks for the suggestions! This method of redirecting from HTTP to HTTPS has been documented here:

https://docs.acquia.com/articles/redirecting-traffic-between-http-and-ht...

jpmcneal@gmail.com's picture
jpmcneal
Points: 0

I think there's at least one more additional step to enabling all traffic to pass over https:

  1. Click the down-arrow inside the environment header (Dev, Stage, or Prod) of the site you want to accessed over https
  2. In the menu that appears, select "Configure"
  3. Under "Varnish settings" check the box labelled "Varnish through SSL"
  4. Click save
colan.schwartz@chapterthree.com's picture
colan.schwartz
Points: 1

It appears as though the only way to make the configuration changes is by editing the default .htaccess. I don't recommend this practice because you'll then have to cherry-pick that commit after every core update as it'll get overwritten.

The best place to put this clause is in the Web server configuration, outside of the Drupal docroot. However, it appears as though we're not given access to these config files.

So we need a better solution, like putting something in settings.php (which doesn't ship with core, and therefore won't get overwritten).

Status Change: 
Unresolved