Apologies in advance for contributing to what must already be an exhaustive list of questions related to .htaccess redirects. My question concerns a client website consisting of multiple language versions, the folder structure being as follows:
index.html (default german version)
— en
index.html
— fr
index.html
— nl
index.html
– css
– img
– js
Said client now asked me to implement a language redirect which I did by moving the default german version to its own subfolder and placing the following .htaccess in the root directory.
RewriteEngine On
# Redirect to dutch language version
RewriteCond %{HTTP:Accept-language} ^(nl.*) [NC]
RewriteRule ^$ /nl/ [L,R=302]
# Redirect to french language version
RewriteCond %{HTTP:Accept-language} ^(fr.*) [NC]
RewriteRule ^$ /fr/ [L,R=302]
# Redirect to english language version
RewriteCond %{HTTP:Accept-language} ^(en.*) [NC]
RewriteRule ^$ /en/ [L,R=302]
# Redirect all other languages to english language version
RewriteCond %{HTTP:Accept-language} !^(nl|fr|de|en).* [NC]
RewriteRule ^$ /en/ [L,R=302]
# Redirect to german language version
RewriteCond %{HTTP:Accept-language} ^(de.*) [NC]
RewriteRule ^$ /de/ [L,R=302]
The redirects themselves work as they should and don’t conflict with the manual language selector on each respective page. The only problem I am left with is that the URL shown in the browser includes the subfolder for the respective language, i.e:
mydomain.com/de/
mydomain.com/en/
mydomain.com/fr/
mydomain.com/nl/
While this is intended for the non-default languages (i.e. en, fr and nl), the URL should show the root address when visiting the default german version:
mydomain.com
instead of
mydomain.com/de/
How would I need to modify my .htaccessfile to achieve the desired behavior? I am testing the site from within a subfolder on the sites server called dev so the suggested solution should ideally work with mydomain.com and dev.mydomain.com alike.
Thanks very much in advance.