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 OnRewriteCond %{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} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-lRewriteRule ^(en|de|nl|fr|es)$ index.php?lang=$1 [L,QSA]
.htaccess language redirects with SEO-friendly URLs
htaccess;mod rewrite;redirects
You're almost there. Drop the very first RewriteCond (as it's not required and won't match ever) and add a trailing / to your last RewriteRule since you're redirecting with them.RewriteEngine OnRewriteCond %{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} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-lRewriteRule ^(en|de|nl|fr|es)/?$ index.php?lang=$1 [QSA,NC,L]