Skip to content
Snippets Groups Projects

Pantheon forced redirects

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Erick Hitter
    Edited
    forced-redirect.php 825 B
        if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'cli' !== php_sapi_name() ) {
    		switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) {
    		    case 'live':
    				$primary_domain = 'www.directrelief.org';
    				break;
    
    			default:
    				$primary_domain = $_ENV['PANTHEON_ENVIRONMENT'] . '-directrelief.pantheonsite.io';
    				break;
    		}
    
    		if (
    			$_SERVER['HTTP_HOST'] !== $primary_domain ||
    			! isset( $_SERVER['HTTP_USER_AGENT_HTTPS'] ) ||
    			'ON' !== $_SERVER['HTTP_USER_AGENT_HTTPS']
    		) {
    			// Name transaction "redirect" in New Relic for improved reporting.
    			if ( extension_loaded( 'newrelic' ) ) {
    				newrelic_name_transaction( 'redirect' );
    			}
    
    			header( 'HTTP/1.0 301 Moved Permanently' );
    			header( 'X-Redirect: primary-domain' );
    			header( 'Location: https://' . $primary_domain . $_SERVER['REQUEST_URI'] );
    			exit;
    		}
    	}
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment