"All the stuff around the edges is the same on every page. In the middle where I expected to find a bunch of unique content, there are only a few words-- and one of them is 'no'."
Yah. Your average robot should be able to manage that.
Remedy in simplest form:
--before starting to build page, turn on output buffer
--once you reach the point where your code determines that there is or is not material to make a "real" page, send out your response header, either 200 or 404
--now release the contents of the buffer and, if necessary, finish building the page
The sole purpose of the buffer is to buy your server some time before it has to send out a response header, since this can only be done before the user has seen even a single byte of the page.