Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aloyr/c73f9fd3310a4ee4f5d12fefd8f55ac5 to your computer and use it in GitHub Desktop.
Save aloyr/c73f9fd3310a4ee4f5d12fefd8f55ac5 to your computer and use it in GitHub Desktop.
multiple redirects
// 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