Skip to content

Instantly share code, notes, and snippets.

@dherbold
Created August 6, 2017 20:48
Show Gist options
  • Save dherbold/78891a7789b491a292de057ffeffb7e6 to your computer and use it in GitHub Desktop.
Save dherbold/78891a7789b491a292de057ffeffb7e6 to your computer and use it in GitHub Desktop.
/ Redirect all traffic to non-www. For example yoursite.com
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) &&
($_SERVER['PANTHEON_ENVIRONMENT'] === 'live') &&
// Check if Drupal or WordPress is running via command line
(php_sapi_name() != "cli")) {
if ($_SERVER['HTTP_HOST'] == 'www.youwebsite.com') {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://yourwebsite.com'. $_SERVER['REQUEST_URI']);
exit();
}
}
// Require HTTPS.
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) &&
($_SERVER['HTTPS'] === 'OFF') &&
// Check if Drupal or WordPress is running via command line
(php_sapi_name() != "cli")) {
if (!isset($_SERVER['HTTP_X_SSL']) ||
(isset($_SERVER['HTTP_X_SSL']) && $_SERVER['HTTP_X_SSL'] != 'ON')) {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment