Instantly share code, notes, and snippets.

Embed
What would you like to do?
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