Skip to content

Instantly share code, notes, and snippets.

@gsahatqija
Forked from markhowellsmead/.htaccess
Created July 14, 2021 09:25
Show Gist options
  • Save gsahatqija/506ff981121a231c195080ca6cd4ecc6 to your computer and use it in GitHub Desktop.
Save gsahatqija/506ff981121a231c195080ca6cd4ecc6 to your computer and use it in GitHub Desktop.
Detect browser language and redirect to appropriate language version of the website
# Redirect visitors to the root domain path (e.g. www.mywebsite.ch) to the appropriate language version
# Fallback to English version if no matching browser language defined
# Based on language version being at e.g. www.mywebsite.ch/de/
# language is ES-MX (Mexico)
RewriteCond %{HTTP:Accept-Language} ^es-mx [NC]
RewriteRule ^$ /mx/ [L,R=301]
# language is ES-ES (Spain)
RewriteCond %{HTTP:Accept-Language} ^es-es [NC]
RewriteRule ^$ /es/ [L,R=301]
# language starts with DE
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ /de/ [L,R=301]
# language starts with FR
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
# language starts with IT
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteRule ^$ /it/ [L,R=301]
# else redirect to the English version
RewriteRule ^$ /en/ [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment