Thank you for your message.
You're correct that the current implementation redirects all 404 errors to a fixed alias (foutpagina-404), which works for the default language but doesn't account for multilingual setups. To ensure proper redirection based on the active language, you’ll need to enhance your error.php logic to dynamically detect the language and redirect accordingly.
Below is an improved version of your code that handles multilingual 404 redirects by detecting the current language and mapping it to the appropriate alias:
$app = Factory::getApplication();
$lang = $app->getLanguage()->getTag(); // e.g., 'en-GB', 'nl-NL'
$config = Factory::getConfig();
$sef = $config->get('sef');
$sef_rewrite = $config->get('sef_rewrite');
$sef_suffix = $config->get('sef_suffix');
// Define language-specific aliases
$languageRedirects = [
'en-GB' => 'error-page-404', //replace with the URL of the page that you have copied for this language
'nl-NL' => 'foutpagina-404', //replace with the URL of the page that you have copied for this language
];
// Default to base URL
$redirect_url = Uri::base();
// Build redirect URL based on language
if (isset($languageRedirects[$lang])) {
$alias = $languageRedirects[$lang];
if (!$sef_rewrite) {
$redirect_url .= 'index.php/';
}
$redirect_url .= $alias;
if ($sef_suffix) {
$redirect_url .= '.html';
}
}
// Trigger redirect on 404
if ($this->error->getCode() == 404) {
header('Location: ' . $redirect_url, true, 301);
exit;
}
This approach ensures users are redirected to the correct 404 page based on their selected language. Just be sure to update the aliases (or page IDs) to match your actual menu items.
Best regards