Skip to content

Instantly share code, notes, and snippets.

@mpezzi
Created April 18, 2012 13:17
Show Gist options
  • Save mpezzi/2413502 to your computer and use it in GitHub Desktop.
Save mpezzi/2413502 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 = '/';
}
@tommymetz
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment