Language-specific redirect not working

Hey

the following rule works:

[[redirects]]
  status = 200
  from = "/*"
  to = "/de/index.html"

But this does not kick in as soon as I add a language condition:

# Auto-redirects by language
[[redirects]]
  from = "/*"
  to = "/de/index.html"

  status = 200

  # Redirect based on browser language
  conditions = {Language = ["de"]}

When I look for my browser settings in JS I get this:

navigator.language
--> "de"

What am I doing wrong?

Hi, @Jan, and welcome to our Netlify community site. Would you please send us a link to the site at Netlify or the API ID for the site?

The API ID (the ID not the key) is safe to share publicly if you don’t want to share the subdomain. The API ID is found under “Site Name” > Settings > General > Site information.

Hi Jan,

is your browser sending more than one language in the request header?

If so it’s a known issue. See this thread.

Sorry for the late reply. The site ID is 9e58d025-8a53-41d3-b96a-c462d20cc03c

I suspect it has to do with the multiple headers problem. I just played around with the build and the netlify.toml and I could not get it to work.

Headers & Failed Requests

Netlify.toml

[build]

  # Directory (relative to root of your repo) that contains the deploy-ready
  # HTML files and assets generated by the build. If a base directory has
  # been specified, include it in the publish directory path.
  publish = "build"

  # Default build command.
  command = "npm run build-i18n"

# SPA support for german locale
[[redirects]]
  from = "/de/*"
  to = "/de/index.html"

# SPA support for english locale
[[redirects]]
  from = "/en/*"
  to = "/en/index.html"

# Auto-redirects by language for German
[[redirects]]
  from = "/*"
  to = "/de/index.html"
  force = true

  # The default HTTP status code is 301, but you can define a different one.
  status = 200

  # Redirect based on browser language, geolocation, and/or identity role.
  conditions = {Language = ["de"]}

# Redirect rule for English
[[redirects]]
  from = "/*"
  to = "/en/index.html"
  force = true

  # The default HTTP status code is 301, but you can define a different one.
  status = 200

  # Redirect based on browser language, geolocation, and/or identity role.
  conditions = {Language = ["en"]}

# Redirect rule for English
[[redirects]]
  from = "/*"
  to = "/en/index.html"
  force = true

  # The default HTTP status code is 301, but you can define a different one.
  status = 200

  # Redirect based on browser language, geolocation, and/or identity role.
  conditions = {Language = ["en-US"]}

# Default language is english
# [[redirects]]
#   status = 200
#   from = "/*"
#   to = "/en/index.html"

Yup, unfortunately it does map to the problem that @ndalliard linked (thanks for that!). We’ve linked this thread to that bug report too, so we can let you know when things change. The team is actively working on an overhaul of our redirects system that will fix many issues likely including this one, and hoping to launch in the next couple of months.

That doesn’t really help you today, but it is on our roadmap and we do intend to fix it (which is not something we’ll lie about if we don’t have firm plans).