Created
June 19, 2018 16:16
-
-
Save joedooley/e4fe3c8bc5f5c5aec80d880e7d935b42 to your computer and use it in GitHub Desktop.
Standardize on HTTPS for all Pantheon Environments
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
<?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