Plugin – Proper way to handle 404 pages?

The proper hook to handle custom 404 content is 404_template. This happens when WordPress is trying to include the default template, but before any HTTP headers have been sent.

So you can change the template, send or overwrite HTTP headers, and all of that without any checks, because WordPress has done that for you already.

In most cases you should not redirect those requests. A redirect is a 3xx status, not a 4xx.

You might find some inspiration in my old 404 plugin.