If no static page found, redirect request to subdomain?

Currently I have static pages deployed (w/CF Pages) on the root of my primary domain, for the purposes of this post lets call it bob.com

So if you goto bob.com you get a static landing page, and you can browse to a few other static pages such as bob.com/contact or bob.com/pages/terms, etc.

There’s also a SPA that lives at a.bob.com (also deployed using CF Pages), and what I’d like to do is have users be able to use bob.com/:username which, if no static route is found, should redirect them to a.bob.com/:username.

Is this something that’s possible to do? I’ve looked into workers and page functions, but haven’t quite been able to determine how to achieve this use-case. Thank you!

You might want to look into Bulk Redirects and Dynamic Redirects for this.

AFAIK, Pages can only handle 404s with a a 404.html file. Short of putting a Worker in front of it to monitor for a 404 response, I don’t know how else you can dynamically redirect a 404. In which case all 404s will redirect to whatever random page someone tries to access at bob.com, which may lead to unexpected behavior.