Skip to content

Instantly share code, notes, and snippets.

@sewmyheadon
Last active January 17, 2018 00:36
Show Gist options
  • Save sewmyheadon/828669f1fc388fe9120ccbfc05a33b71 to your computer and use it in GitHub Desktop.
Save sewmyheadon/828669f1fc388fe9120ccbfc05a33b71 to your computer and use it in GitHub Desktop.
how to redirect multiple urls at pantheon
// 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