diff --git a/core/func/main.php b/core/func/main.php index 91fcf54..b527621 100755 --- a/core/func/main.php +++ b/core/func/main.php @@ -383,4 +383,38 @@ } return $g_lang[$name]; } + + // Requare redirect + function GetRedirectURL() + { + global $g_arrLangs; + // Language doesn't have special domain. + if (!isset($g_arrLangs[LANG]['domain'])) + { + return NULL; + } + $newDomain = $g_arrLangs[LANG]['domain']; + + // If we have any params then ignore redirect. + if (count(array_values($_GET)) > 1) + { + return NULL; + } + + // Skip for localhost + if (strcasecmp($_SERVER['SERVER_NAME'], '127.0.0.1') == 0 + || + strcasecmp($_SERVER['SERVER_NAME'], 'localhost') == 0) + { + return NULL; + } + + // Domain is the same. + if (strcasecmp($_SERVER['SERVER_NAME'], $newDomain) == 0) + { + return NULL; + } + + return $_SERVER['REQUEST_SCHEME'] . "://" . $newDomain . $_SERVER['REQUEST_URI']; + } ?> diff --git a/core/init/main.php b/core/init/main.php index 6a62c4b..b1b5fbd 100755 --- a/core/init/main.php +++ b/core/init/main.php @@ -4,7 +4,13 @@ header('Content-type: text/html; charset=' . $g_config['charset']); GetQuery(); // Что бы определился язык сайта - + $redirectUrl = GetRedirectURL(); // Check redirect + if ($redirectUrl != NULL) + { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: $redirectUrl"); + exit(); + } // Подключаем все языковые файлы из автозагруки $dirs = array_unique( array( diff --git a/src/home.php b/src/home.php index 92464d1..fd49bee 100755 --- a/src/home.php +++ b/src/home.php @@ -1,6 +1,7 @@