I have next.js app with two domains. The second domain redirects to a sub-path of the first one. Navigating to the second domain or refreshing the page gives randomly a 404 error, especially with a clear cache (e.g., a new incognito tab).
You can test the randomly breaking redirect here: https://test2.map.avoin.org/
The netlify address is https://hiilikartta-deploy-test–avoin-map-test.netlify.app/
The build is using Next.js 14.2.3 and the V5 Next.js runtime.
Here is my netlify.toml
[[redirects]]
from = "https://test2.map.avoin.org/_next/*"
to = "https://test.map.avoin.org/_next/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/adds/*"
to = "https://test.map.avoin.org/adds/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/api/*"
to = "https://test.map.avoin.org/api/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org"
to = "https://test.map.avoin.org/hiilikartta"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/*"
to = "https://test.map.avoin.org/hiilikartta/:splat"
status = 200
force = true
Thanks for any help or insights!
The problem is because you’re using a custom domain in the redirect path. Try changing the redirects to (all redirects):
[[redirects]]
from = "https://test2.map.avoin.org"
to = "https://avoin-map-test.netlify.app/hiilikartta"
status = 200
force = true
Thank you for the response! However, now the redirects always give a 404.
[[redirects]]
from = "https://test2.map.avoin.org/_next/*"
to = "https://avoin-map-test.netlify.app/_next/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/adds/*"
to = "https://avoin-map-test.netlify.app/adds/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/api/*"
to = "https://avoin-map-test.netlify.app/api/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/hiilikartta"
to = "https://avoin-map-test.netlify.app/hiilikartta"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/*"
to = "https://avoin-map-test.netlify.app/hiilikartta/:splat"
status = 200
force = true
If I use the branch deploy URL in combination with the test.map.avoin.org domain it kinda works:
[[redirects]]
from = "https://test2.map.avoin.org/_next/*"
to = "https://hiilikartta-deploy-test--avoin-map-test.netlify.app/_next/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/adds/*"
to = "https://hiilikartta-deploy-test--avoin-map-test.netlify.app/adds/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/api/*"
to = "https://hiilikartta-deploy-test--avoin-map-test.netlify.app/api/:splat"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/hiilikartta"
to = "https://test.map.avoin.org/hiilikartta"
status = 200
force = true
[[redirects]]
from = "https://test2.map.avoin.org/*"
to = "https://test.map.avoin.org/hiilikartta/:splat"
status = 200
force = true
Interestingly, the website breaks if I replace the last redirect with this:
[[redirects]]
from = "https://test2.map.avoin.org/*"
to = "https://hiilikartta-deploy-test--avoin-map-test.netlify.app/hiilikartta/:splat"
status = 200
force = true
So any sub-path of /hiilikartta will give a 404. There is clearly something wrong with something. And I would rather not have to use the branch domain. Any ideas? Thanks!
Yes, because now they’re consistently being matched correctly.
You can use any netlify.app
URL. Using custom domains in rewrites is not recommended.
Do you have a link to a deploy with these attempts:
Hi there!
Thanks for following up, and my sincere apologies for the delay! Can you let us know if you’re still running into this issue? In reviewing/refreshing the above permalinks, I’m unable to currently replicate any 404
errors at the above routes, so any live examples will help our team dig back in.