Skip to content

Instantly share code, notes, and snippets.

@lorenzulrich
Created March 31, 2015 18:37
Show Gist options
  • Save lorenzulrich/e3533fb3a450e09ede41 to your computer and use it in GitHub Desktop.
Save lorenzulrich/e3533fb3a450e09ede41 to your computer and use it in GitHub Desktop.
Multi-language page not found handling for TYPO3 CMS
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_redirectPageID'] = 4690;
<?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']);
}
}
'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