Alter existing page contents based on url

I belive this will work for you:

Create a “page” called “stuff”, then create another page called “foo”, make it child of “stuff”, now stuff/foo will exist and won’t be 404.

Finally use the_content filter and make the required data manipulation.

The other choice (hard way) you’d have is to use pre_get_post hook, so you can make wordpress believe it’s really “foo” page that’s being requested, and avoid 404.