Last active
January 17, 2018 00:36
-
-
Save sewmyheadon/828669f1fc388fe9120ccbfc05a33b71 to your computer and use it in GitHub Desktop.
how to redirect multiple urls at pantheon
This file contains hidden or 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
// List of old urls and corresponding new target urls. | |
$redirects = array( | |
'/url_01' => '/new-url-01', | |
'/url_02' => '/new-url-02', | |
); | |
// Redirect multiple old to new urls. | |
// Note: make sure environment is set correctly | |
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && | |
( $_ENV['PANTHEON_ENVIRONMENT'] === 'dev' ) && | |
// Check if Drupal or WordPress is running via command line | |
( php_sapi_name() != "cli" ) ) { | |
if ( in_array( $_SERVER['REQUEST_URI'], $redirects ) ) { | |
$_SERVER['REQUEST_URI'] = $redirects[ $_SERVER['REQUEST_URI'] ]; | |
} | |
header( 'HTTP/1.0 301 Moved Permanently' ); | |
header( 'Location: http://www.mydomain.com' . $_SERVER['REQUEST_URI'] ); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment