I’m trying to setup a multi-locale next.js website on Netlify. The website has two domains configured and I assumed that Automatic Locale Detection should work fine with Domain Routing (it does on Vercel), but no redirect happens on Netlify.
This wouldn’t be a big issue because in the end it’s just a language based redirect on
/ so I started looking into Netlify redirect definitions. First using the
_redirects file, but no matter what I’m doing the redirects are not picked up (e.g. checking the total number of redirect rules in the deploy output). So I moved to the netlify.toml definitions, which are picked up fine during the deploy. But they also don’t seem to work. Not just language based redirects but pretty basic rules like:
[[redirects]] from = "https://www.example.com" to = "https://example.com" status = 301 force = true [[redirects]] from = "http://www.example.com" to = "https://example.com" status = 301 force = true [[redirects]] from = "https://www.example.com/" to = "https://example.com" status = 301 force = true [[redirects]] from = "http://www.example.com/" to = "https://example.com" status = 301 force = true
(To my understanding the trailing slash version should not be required, but I added it just to be on the safe side.)
The www page still happily returns a 200 OK response and renders the main page:
❯❯❯ http -h https://www.example.com HTTP/1.1 200 OK age: 0 cache-control: public, max-age=0, must-revalidate content-encoding: gzip content-type: text/html; charset=UTF-8 date: Thu, 01 Apr 2021 13:23:30 GMT etag: "xxx" server: Netlify transfer-encoding: chunked vary: Accept-Encoding x-nf-request-id: xxx
What does work fine is a splat based definition:
[[redirects]] from = "https://www.example.com/*" to = "https://example.com/:splat" status = 301 force = true
❯❯❯ http -h https://www.example.com/xxx HTTP/1.1 301 Moved Permanently Age: 0 Cache-Control: public, max-age=0, must-revalidate Connection: keep-alive Content-Length: 38 Content-Type: text/plain; charset=utf-8 Date: Thu, 01 Apr 2021 13:58:25 GMT Location: https://example.com/xxx Server: Netlify X-NF-Request-ID: xxx
I did read and work myself through the Redirects Support Guide, but it did not help either. Am I missing something obvious here? Thanks for your help!