Hi,
We set up the automatic language detection for our new website in the site header. If a customer is visiting fairtiq.com/ they are supposed to be redirected to either the German, French or English version, based on their browser language. (FAIRTIQ - The easiest public transport ticket., FAIRTIQ - Die einfachste Fahrkarte., FAIRTIQ - Le billet le plus simple.)
The language detection seems to work, but as you can see in the log below it fetches the 404 page in the background, which might have negative impact on SEO or other.
Is there a way to avoid this? Did we miss anything?
HTML code:
<script>
function redirectToPreferredLanguage() {
if (window.location.pathname !== '/') {
return;
}
const lang = navigator.language;
const languageConfig = {
de: '/de',
fr: '/fr',
en: '/en'
};
const defaultLanguage = 'de';
const userLanguage = Object.keys(languageConfig).find(language => lang.includes(language));
const redirectLanguage = userLanguage
? languageConfig[userLanguage] || languageConfig[defaultLanguage]
: languageConfig[defaultLanguage]
window.location = languageConfig[userLanguage] || languageConfig[defaultLanguage];
}
redirectToPreferredLanguage();
</script>
Thanks for your help.
