RewriteRule ^en/ - [L]
RewriteRule ^de/ - [L]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^ /de%{REQUEST_URI} [L]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^ /en%{REQUEST_URI} [L]
Just curious, how does it work, have you tested these by any chance?
Also – These different multilingual websites will their own .htaccess files, in which of the .htaccess files is the above code to be written?
Thanks!
]]>The first two rules prevent the other rules from being used when a specific language has already been requested. When browsers send requests to your server, they send a header that tells servers their preferred language. The %{HTTP:Accept-Language}
variable is assigned whatever value the browser sent. The second pair of rules rewrites the request to the /de/ folder when the preferred language code begins with “de”.
Same goes for the last pair when the preferred language code begins with “en”. “en-US”, “en-GB”, “en”, etc. all will match the ^en
parameter.