Skip to content

Instantly share code, notes, and snippets.

@ari-gold
Last active August 29, 2015 14:20
Show Gist options
  • Save ari-gold/b88c6a4192985dfa3298 to your computer and use it in GitHub Desktop.
Save ari-gold/b88c6a4192985dfa3298 to your computer and use it in GitHub Desktop.
if (defined('PANTHEON_ENVIRONMENT')) {
/**
* Handle Subdomain Redirects.
*/
if ($_SERVER['PANTHEON_ENVIRONMENT'] === 'live') {
switch ($_SERVER['HTTP_HOST']) {
// Remove WWW.
case 'www.patch.com':
case 'live-patch-fe.pantheon.io':
header('HTTP/1.0 301 Moved Permanently');
header('Location: http://patch.com' . $_SERVER['REQUEST_URI']);
exit();
// Map <something>.patch.com to patch.com/<something> and let
// custom_router_url_inbound_alter() issue a 301 redirect to the
// full path including state term
default:
$subdomain = str_replace('patch.com', '', $_SERVER[HTTP_HOST]);
if (strpos($subdomain, '.')) {
$_SERVER[HTTP_HOST] = 'patch.com';
$_GET['q'] = str_replace('.', '', $subdomain) . DIRECTORY_SEPARATOR . $_GET['q'];
}
break;
}
}
// Remove WWW.
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) &&
$_SERVER['PANTHEON_ENVIRONMENT'] === 'live') {
if ($_SERVER['HTTP_HOST'] == 'www.patch.com' ||
$_SERVER['HTTP_HOST'] == 'live-patch-fe.pantheon.io') {
header('HTTP/1.0 301 Moved Permanently');
header('Location: http://patch.com'. $_SERVER['REQUEST_URI']);
exit();
}
}
@ari-gold
Copy link
Author

Should line 30 onward be on patch-services, not patch-redirects?

@jppatchkid
Copy link

Ah, that was all intended to be on patch frontend... Line 30 on was removed from the previous version and replaced with the top half

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment