Issue
- The language selector in Liferay DXP uses the
/c/portal/update_languageURL, which calls theUpdateLanguageAction.javaaction. This action sets the selected language and redirects the user to the translated page with a 302 response. This extra HTTP request adds overhead and might impact SEO. - Is there a way to configure the language selector to bypass this redirect and link directly to the translated page URL?
Environment
- Liferay DXP 2024.Q1 (Quarterly Release)
Resolution
Create a custom Application Display Template (ADT) to generate language links that point directly to the final friendly URL for each language. This method avoids the extra redirect through UpdateLanguageAction. Here's an example:
<div> <a href="/en/test-page">English</a> <a href="/es/pagina-de-prueba">Español</a> <a href="/fr/page-de-test">Français</a> </div>
Within your custom ADT, ensure the appropriate friendly URLs are generated dynamically for each supported language. This direct linking approach improves SEO by reducing redirects and HTTP requests.