Skip to content

Instantly share code, notes, and snippets.

@dherbold
Created October 2, 2017 18:05
Show Gist options
  • Save dherbold/1b9fb5fdff732adfe9d9222ce02aeee1 to your computer and use it in GitHub Desktop.
Save dherbold/1b9fb5fdff732adfe9d9222ce02aeee1 to your computer and use it in GitHub Desktop.
require https before bootstrap + redirect to naked domain
// 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.cast.asu.edu') {
header('HTTP/1.0 301 Moved Permanently');
header('Location: http://cast.asu.edu'.$_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