Applies to multi-lingual Joomla websites with mod_rewrite and SEF URLs turned on.
In the Joomla plugin "System - Language Filter", there is an option to "Remove URL Language Code". See attached screenshot.
This feature removes the language code from the URL for the websites default language. So for example, with English set as the default site language, this option would remove /en/ from the URL.
This feature works as expected. But the Language Switcher Module is not aware of this option when a user is viewing a non-EN page.
For example, if I am on a page in Thai, the URL might be something like:
If I use the language switcher to change to English, the alternate URL will be constructed with the /en/ language code:
Which then 301 redirects to:
When the "Remove URL Language Code" feature is enabled, the language switcher module should not include the language code for the default site language. Using the example above, it should link to this URL
The language switcher module does include the language code, triggering an unnecessary 301 redirect. This causes an extra server request, delays the user experience and wastes SEO crawl budget.
Setting | Value
Database Type | mysql
Database Version | 5.7.25-log
Database Collation | latin1_swedish_ci
Database Connection Collation | utf8mb4_general_ci
PHP Version | 7.3.6
Web Server | Apache
WebServer to PHP Interface | cgi-fcgi
Joomla! Version | Joomla! 3.9.8 Stable [ Amani ] 11-June-2019 20:00 GMT
Joomla! Platform Version | Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
On large websites, this can be an impactful optimisation that helps improve the user experience, optimise server resources and improve SEO by conserving crawl budget and potentially consolidating pagerank.
Please can a Bug Squad Team-Member answer as this Issue is opened more than 12 hours ago?
afaik we do absolutely need to include the 'sef' prefix when using Remove Language Code, even if the final result is to not display it for Search Engines for the site default language.
The redirects are done on purpose and the switcher is not at stake.
@infograf768 Thanks for the feedback! But why is this absolutely needed? Couldn't the front-end logic be set up to exclude the default language code when that option is enabled? Joomla seems to operate this way when viewing the site in the default language.
Meaning, if I am viewing a site in English (the default) and I navigate to the language switcher, the URL does not include /en/. But if I'm on a non-EN page, then the /en/ prefix is included. So this scenario creates an extra redirect, which is much better than not having it, but still not ideal.
Basically, a new user has no cookie set or the cookie has expired.
Let's say the default site language is set to en-GB (sef prefix is "en". But the user browser preferred language is set to it-IT (sef is "it")
When this user tries to load
mysite.com/ from somewhere on the web, Joomla checks the browser default language and IF it finds it, redirects to
mysite.com/it/ and NOT to the en-GB version.
same for en-GB if preferred browser language is en-GB, it will redirect to
Joomla understands that and will modify the url to not display the sef prefix.
Note: It is important to set your site map with the prefix for each language.