Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda