404.html Files in Subdirectories Not Used

I have a multilingual Hugo website on Cloudflare Pages. I have a 404.html file at the root and a localized version under each lang subdirectory (ie. /en/404.html, /de/404.html and so forth). The documentation says:
Pages will then attempt to find the closest 404 page. If one is not found in the same directory as the route you are currently requesting, it will continue to look up the directory tree for a matching 404.html file, ending in /404.html.
This implies that if the URL is something like example.com/de/foobar, it should use the 404.html under the /de/ directory. However, it looks like the 404.html at the root is always used. Have I misunderstood something, or is this functionality broken?
5 Replies
juha
juha2mo ago
No guesses what might be going on?
Chaika
Chaika2mo ago
Functionality looks fine to me, here's an example project with custom 404s stating which directory they are under: https://4o4.pages.dev/doesntexist https://4o4.pages.dev/lang/doesntexist https://4o4.pages.dev/lang/inner/doesntexist
No description
Chaika
Chaika2mo ago
GitHub
workers-sdk/packages/pages-shared/asset-server/handler.ts at 593628...
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - cloudflare/workers-sdk
Chaika
Chaika2mo ago
If you have an advanced mode function (_worker.js), could be messing with it, although Hugo shouldn't have that out of the box. Otherwise would be helpful to show your assets uploaded/pages.dev
juha
juha2mo ago
Thanks. Looks like the 404 pages are missing in Assets uploaded, but they are generated on my local dev environment when I run Hugo. Curious. I have them in the layouts folder, and Hugo should (and does on my dev machine) generate the final 404.html files inside the lang folders. So layouts/404.en.html should end up in /en/404.html, but for some reason this doesn't happen when the site is build on Cloudflare. Okay, problem solved. I added an environment variable HUGO_VERSION and gave it the value 0.134.1 (latest Hugo version). Now the 404 pages are generated and applied as they should. @Chaika Thank you for pointing me to the Assets uploaded tab, I hadn't noticed it before.
Want results from more Discord servers?
Add your server