Hi! I’m still trying to wrap my head around how to handle redirects properly. I have a multi-domain site, deployed from the same repo but different domains rewriting to different paths, like so: https://www.lapoint.ch/* /de-ch/:splat 200
How do I utilize the /de-ch/404.html file that I’m building? All I’m getting is the built in netlify 404 page no matter what I seem to try.
Hey! Firstly I’d say take a look at deploy contexts and you might like to redirect by conditions (language and country), you can view those here: File-based configuration | Netlify Docs
In the instance above for your redirect I think you could do something like /de-ch/* /de-ch/404 404
I think this should redirect any route that does not already exist to your 404 with a 404 error code.
I would still recommend looking at the links above and I personally find the syntax of netlify.toml redirect with conditions much nicer to understand.
IE: Language redirect without netlify toml: /* /de-ch/:splat 302 Language=de-ch
with netlify.toml
[[redirects]]
from = “/”
to = “/es”
status = 302
force = true
conditions = {Country = [“ES”]}
If you go to netlify and view your deploys can you click on the latest one and send the URL. However, I think these are only able to be public if your repo is public too
What I wanted to see is in your deploy details that is states the redirects have been processed? It would be much easier to debug with a public repo for a while but understand if you cant
edit:
I just loaded your site and see youre using React, could you not handle this via React Router?
and then set _redirects to be /* /index.html 200?
Client side can’t handle 404s no. The site is statically prerendered and then progressively turns into a dynamic client side application. 301s and 404s have to be handled on the server side of things.
The repo cannot be public I’m afraid, but here’s some info from the latest deploy:
View this: Redirect options | Netlify Docs
I would make sure you add ! to the end of your redirect rules and make sure all the domains are added to the site.
Suggestions below from previous edit:
Im out at the moment but an idea could be to have a main domain that would then redirect to your https://www.lapoint.dk/.se/.no domains dependent on the country code. Such as:
/* https://www.lapoint.dk/:splat 302 Language=de-ch (I don’t know the codes so dk and de-ch might not make sense but you get the point?).
OR
You could have one route domain for good and only change your language based on country code?
lets say you choose .dk as your domain so it is https://www.lapoint.dk then you could do
/* /de-ch/:splat 302 Language=de-ch
when the language is set to de-ch it will route everything through /de-ch first?
I appreciate you trying to help, but I’m not doing redirects from absolute domains. I’m doing rewrites and THOSE work, and are according to documentation.
How would you otherwise have different domains for different languages in the same site?
Hey, I’ll tag in @Scott who might be able to give more details.
One extra thing I’ll note is that when you’re doing your redirects to /de-ch/404.html 404, that file needs to actually exist as that’s not a rewrite that will be trying to find the 404 files in that location.
Firstly, can you deploy the 404.html to /de-ch/de-ch/404.html? We have an inkling that this is where the proxy is looking and this would be a quick way to check!
Secondly, can you try re-arranging your redirects file so that a suitable 404 appears above the 200 rule? This is a suspicion because I don’t believe the 404 is being read after the proxy (200) rule is met in the file.
Eager to see if either help!
N.B. I posted the same response in our Helpdesk ticket – happy to continue the conversation in either/both location(s)!
I think it makes sense, for posterity, to continue here then
I first try deploying with /de-ch/de-ch/404.html added but nothing else changed. That did not solve the issue, still only seeing the default 404 page.
I then tried setting the 404s above the 200s rules. Then I see our custom 404, but of course, this stops the redirects from processing since we hit a static file (404.html), so no domain rewrites are in effect and basically the whole site is then down. Had to revert that change immediately because this is a live site.
@Scott This is frankly getting a bit frustrating. The way it seems now it it seems it is not possible to have domain rewrites + custom 404, which frankly is a dealbreaker. We are paying customers and I was expecting this to work or at least to be rectified when one finds these things.
Right now we have migrated just one out of six domains for our site to Netlify, and it seems we cannot go on with the rest? Our client is waiting for this work to be finished.