Last active
September 14, 2017 16:17
-
-
Save JonMcL/9f4b4acd31aee2207dfbeb9269de4081 to your computer and use it in GitHub Desktop.
Redirect to www and https in Pantheon server environments. Add to Drupal 7 settings.php file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pantheon HTTPS and www redirects. | |
*/ | |
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) && php_sapi_name() !== 'cli') { | |
$domain = $_SERVER['HTTP_HOST']; | |
$www_redirect = false; | |
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && $_ENV['PANTHEON_ENVIRONMENT'] === 'live') { | |
if (count(explode('.', $domain)) < 3 && stripos($domain, 'www.') === false) { | |
$domain = 'www.' . $domain; | |
$www_redirect = true; | |
} | |
} | |
if ($www_redirect || !isset($_SERVER['HTTP_X_SSL']) || $_SERVER['HTTP_X_SSL'] != 'ON' ) { | |
header('HTTP/1.0 301 Moved Permanently'); | |
header('Location: https://'. $domain . $_SERVER['REQUEST_URI']); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment