Created
March 31, 2015 18:37
-
-
Save lorenzulrich/e3533fb3a450e09ede41 to your computer and use it in GitHub Desktop.
Multi-language page not found handling for TYPO3 CMS
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
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_redirectPageID'] = 4690; |
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 | |
class user_pageNotFound { | |
/** | |
* Detect language and redirect to 404 error page | |
* | |
* @param array $params "currentUrl", "reasonText" and "pageAccessFailureReasons" | |
* @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfeObj | |
*/ | |
function pageNotFound($params, $tsfeObj) { | |
// get first realurl configuration array (important for multidomain) | |
$realurlConf = array_shift($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']); | |
// look for language configuration | |
foreach ($realurlConf['preVars'] as $conf) { | |
if ($conf['GETvar'] == 'L') { | |
foreach ($conf['valueMap'] as $k => $v) { | |
// if the key is empty (e.g. default language without prefix), break | |
if (empty($k)) { | |
continue; | |
} | |
// we expect a part like "/de/" in requested url | |
if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($params['currentUrl'], '/' . $k . '/')) { | |
$tsfeObj->pageErrorHandler('/index.php?id=' . $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_redirectPageID'] . '&L=' . $v); | |
} | |
} | |
} | |
} | |
// handle default language | |
$tsfeObj->pageErrorHandler('/index.php?id=' . $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_redirectPageID']); | |
} | |
} |
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
'FE' => array( | |
'pageNotFound_handling' => 'USER_FUNCTION:EXT:yourext/Classes/Utility/PageNotFoundHandling.php:user_pageNotFound->pageNotFound', | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment