public static function getRootPageFromUrl() { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getRootPageFromUrl']) && is_array($GLOBALS['TL_HOOKS']['getRootPageFromUrl'])) { foreach ($GLOBALS['TL_HOOKS']['getRootPageFromUrl'] as $callback) { /** @var PageModel $objRootPage */ if (is_object($objRootPage = static::importStatic($callback[0])->{$callback[1]}())) { return $objRootPage; } } } $host = \Environment::get('host'); // The language is set in the URL if (\Config::get('addLanguageToUrl') && !empty($_GET['language'])) { $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, \Input::get('language')); // No matching root page found if ($objRootPage === null) { \System::log('No root page found (host "' . $host . '", language "' . \Input::get('language') . '")', __METHOD__, TL_ERROR); throw new NoRootPageFoundException('No root page found'); } } else { $accept_language = \Environment::get('httpAcceptLanguage'); // Always load the language fall back root if "doNotRedirectEmpty" is enabled if (\Config::get('addLanguageToUrl') && \Config::get('doNotRedirectEmpty')) { $accept_language = '-'; } // Find the matching root pages (thanks to Andreas Schempp) $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, $accept_language); // No matching root page found if ($objRootPage === null) { \System::log('No root page found (host "' . \Environment::get('host') . '", languages "' . implode(', ', \Environment::get('httpAcceptLanguage')) . '")', __METHOD__, TL_ERROR); throw new NoRootPageFoundException('No root page found'); } // Redirect to the website root or language root (e.g. en/) if (\Environment::get('relativeRequest') == '') { if (\Config::get('addLanguageToUrl') && !\Config::get('doNotRedirectEmpty')) { $arrParams = array('_locale' => $objRootPage->language); $strUrl = \System::getContainer()->get('router')->generate('contao_index', $arrParams); $strUrl = substr($strUrl, strlen(\Environment::get('path')) + 1); static::redirect($strUrl, 301); } else { $objPage = \PageModel::findFirstPublishedByPid($objRootPage->id); // Redirect if it is not the language fall back page and the alias is "index" (see #8498) if ($objPage !== null && (!$objRootPage->fallback || $objPage->alias != 'index')) { static::redirect($objPage->getFrontendUrl(), 302); } } } } return $objRootPage; }