.htaccess language redirects with seo-friendly urls
- by jlmmns
How do I setup my .htaccess file to detect several languages, and redirect them to specific seo-friendly urls?
Basically every url needs to go to index.php?lang=(...)
So, for English language detection http://mysite.com has to go to http://mysite.com/en/ (index.php?lang=en)
my .htaccess as of now (not working):
RewriteEngine On
RewriteCond %{HTTP:HOST} http://mysite.com/
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ http://mysite.com/en/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ http://mysite.com/de/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^nl [NC]
RewriteRule ^$ http://mysite.com/nl/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ http://mysite.com/fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^$ http://mysite.com/es/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(en|de|nl|fr|es)$ index.php?lang=$1 [L,QSA]