Last active
November 23, 2017 08:08
-
-
Save pprishchepa/266fd0001c7b308dc31c48d755a499f1 to your computer and use it in GitHub Desktop.
This file contains 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
<?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