Do not redirect to 404, when subpage is missing?

This is a good solution when I know the subpages’ URLs. But I don’t. Basically, I get content for them via REST API. I need something that is described here, but I think for me is enough just redirect to root page