Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Redirecting to subfolder while displaying root URL with .htaccess language redirect and manual language selector

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.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!