Are there any best practices for handling 404 errors in PHP to prevent indexing by search engines like Google?

When a 404 error occurs in PHP, it is important to handle it properly to prevent search engines like Google from indexing these error pages. One way to do this is by redirecting users to a custom error page with a 404 status code. This will ensure that search engines do not index the error page and instead, index the proper content of your website.

<?php
header("HTTP/1.0 404 Not Found");
include('404-error-page.php');
exit();
?>