Skip to content

Instantly share code, notes, and snippets.

@thonixx
Created July 19, 2016 14:35
Show Gist options
  • Save thonixx/dc7c84d1c564d1ff8934738bbf0ff87d to your computer and use it in GitHub Desktop.
Save thonixx/dc7c84d1c564d1ff8934738bbf0ff87d to your computer and use it in GitHub Desktop.
Language handling with RewriteRules only
RewriteEngine on
# Language detection (Fallback is en)
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteCond %{ENV:lang} ^$
RewriteRule ^ - [E=lang:de]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteCond %{ENV:lang} ^$
RewriteRule ^ - [E=lang:fr]
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteCond %{ENV:lang} ^$
RewriteRule ^ - [E=lang:it]
RewriteCond %{HTTP:Accept-Language} ^en [NC,OR]
RewriteCond %{ENV:lang} ^$
RewriteRule ^ - [E=lang:en]
# now the example with a rewriterule
RewriteRule ^/?$ https://%{HTTP_HOST}/index.html#lang=%{ENV:lang} [L,R=301,NE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment