Skip to content

Instantly share code, notes, and snippets.

@pprishchepa
Last active November 23, 2017 08:08
Show Gist options
  • Save pprishchepa/266fd0001c7b308dc31c48d755a499f1 to your computer and use it in GitHub Desktop.
Save pprishchepa/266fd0001c7b308dc31c48d755a499f1 to your computer and use it in GitHub Desktop.
<?php declare (strict_types=1);
// Always redirect to the primary domain when hosted on Wodby.
if (!empty($_SERVER['WODBY_HOST_PRIMARY']) && php_sapi_name() !== 'cli') {
if( preg_match('/^(http[s]?:\/\/)?(.*)$/', $_SERVER['WODBY_HOST_PRIMARY'], $matches)) {
$primary_host = $matches[2];
if ($_SERVER['HTTP_HOST'] !== $primary_host) {
$primary_url = isset($_SERVER['WODBY_URL_PRIMARY'])
? $_SERVER['WODBY_URL_PRIMARY']
: $_SERVER['WODBY_HOST_PRIMARY'];
header('HTTP/1.0 301 Moved Permanently');
header('Location: ' . $primary_url . $_SERVER['REQUEST_URI']);
exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment