Skip to content

Instantly share code, notes, and snippets.

@mostafizpantheon
Last active May 2, 2019 16:17
Show Gist options
  • Save mostafizpantheon/6e7ff1c5326e99bb0833bccda0c886bc to your computer and use it in GitHub Desktop.
Save mostafizpantheon/6e7ff1c5326e99bb0833bccda0c886bc to your computer and use it in GitHub Desktop.
redirect.php
<?php
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && ($_SERVER['HTTP_HOST'] == 'insource.wedc.org') && (php_sapi_name() != "cli")) {
$newurl = 'https://wedc.org/newsletters/archive/' . $_SERVER['REQUEST_URI'];
header('HTTP/1.0 301 Moved Permanently');
header("Location: $newurl");
# Name transaction "redirect" in New Relic for improved reporting (optional)
if (extension_loaded('newrelic')) {
newrelic_name_transaction("redirect");
}
exit();
} else if (isset($_ENV['PANTHEON_ENVIRONMENT']) && php_sapi_name() != 'cli') {
// Redirect to https://$primary_domain in the Live environment
if ($_ENV['PANTHEON_ENVIRONMENT'] === 'live') {
/** Replace www.example.com with your registered domain name */
$primary_domain = 'wedc.org';
} else {
// Redirect to HTTPS on every Pantheon environment.
$primary_domain = $_SERVER['HTTP_HOST'];
}
if ($_SERVER['HTTP_HOST'] != $primary_domain || !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://' . $primary_domain . $_SERVER['REQUEST_URI']);
exit();
}
}
// Redirect subdomain to a specific path.
// Check if Drupal or WordPress is running via command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment