Skip to content

Instantly share code, notes, and snippets.

@joedooley
Created June 19, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joedooley/e4fe3c8bc5f5c5aec80d880e7d935b42 to your computer and use it in GitHub Desktop.
Save joedooley/e4fe3c8bc5f5c5aec80d880e7d935b42 to your computer and use it in GitHub Desktop.
Standardize on HTTPS for all Pantheon Environments
<?php
/**
* Require HTTPS across all Pantheon environments.
* Does not run during wp-cli requests.
*
* This will redirect all pantheon environments redirect to https.
*
* @link https://pantheon.io/docs/redirects/#redirect-to-https
*/
if ( isset($_SERVER['PANTHEON_ENVIRONMENT'] ) && ( $_SERVER['HTTPS'] === 'OFF' ) && ( php_sapi_name() != "cli") ) {
if ( ! isset($_SERVER['HTTP_USER_AGENT_HTTPS'] ) || ( isset($_SERVER['HTTP_USER_AGENT_HTTPS'] ) && $_SERVER['HTTP_USER_AGENT_HTTPS'] !== 'ON') ) {
# Name transaction "redirect" in New Relic for improved reporting (optional)
if ( extension_loaded('newrelic') ) {
newrelic_name_transaction("redirect");
}
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