Skip to content

Instantly share code, notes, and snippets.

@ptierno
Forked from mpezzi/elb.aws.settings.inc
Created December 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptierno/38bccd21355127d7ec4f to your computer and use it in GitHub Desktop.
Save ptierno/38bccd21355127d7ec4f to your computer and use it in GitHub Desktop.
Drupal - Amazon Elastic Load Balancer HTTPS Settings
<?php
/**
* @file
* Amazon Elastic Load Balancer Settings.
*
* Force server to use https:// path if SSL is handled at load balancer.
*
* @see http://drupal.org/node/185161#comment-5452038
*/
// We're running HTTPS natively in the web server.
if ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) {
$base_root = 'https';
}
// We're behind a proxy that talks to the web server via HTTP.
elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) {
$base_root = $_SERVER['HTTP_X_FORWARDED_PROTO'];
}
// There's no HTTPS spoor -- we must be running HTTP.
else {
$base_root = 'http';
}
$base_url = $base_root .= '://'. $_SERVER['HTTP_HOST'];
// $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not be modified by a visitor.
if ( $dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/') ) {
$base_path = "/$dir";
$base_url .= $base_path;
$base_path .= '/';
}
else {
$base_path = '/';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment