Last active
April 18, 2016 15:48
-
-
Save aloyr/c73f9fd3310a4ee4f5d12fefd8f55ac5 to your computer and use it in GitHub Desktop.
multiple redirects
This file contains 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
// Ensure url has 'www' and uses SSL | |
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) && ($_SERVER['PANTHEON_ENVIRONMENT'] === 'live') && | |
(php_sapi_name() != "cli")) { | |
$do_redirect = FALSE; | |
$url_chunks = explode('.', $_SERVER['HTTP_HOST']); | |
if ($url_chunks[0] != 'www') { | |
array_unshift($url_chunks, 'www'); | |
$do_redirect = TRUE; | |
} | |
if (strtolower($_SERVER['HTTPS']) != 'on') { | |
$do_redirect = TRUE; | |
} | |
if ($do_redirect) { | |
$new_url = 'https://' . implode('.', $url_chunks) . $base_path . request_path(); | |
header('Location: ' . $new_url, TRUE, 301); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment