.htaccess language redirects with seo-friendly urls

Posted by jlmmns on Pro Webmasters See other posts from Pro Webmasters or by jlmmns
Published on 2013-10-07T11:12:20Z Indexed on 2013/10/21 22:05 UTC
Read the original article Hit count: 305

Filed under:
|
|

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]

© Pro Webmasters or respective owner

Related posts about htaccess

Related posts about mod-rewrite