I was able to make it work by doing this in the wrangler config (see last line):
# Configure Cloudflare Worker
name = 'hosting-cloudflare-worker'
compatibility_date = "2025-05-26"
[build]
command = "./build.sh"
[assets]
directory = "./public"
not_found_handling = "404-page"
Then publish one or more 404.html
files in the same way that you did for CF Pages.
You can define a custom page to be displayed when Pages cannot find a requested file by creating a
404.html
file. 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 matching404.html
file, ending in/404.html
. This means that you can define custom 404 paths for situations like/blog/404.html
and/404.html
, and Pages will automatically render the correct one depending on the situation.
https://developers.cloudflare.com/pages/configuration/serving-pages/#not-found-behavior