How does server-side execution of PHP header location redirects affect their impact on search engine indexing?

When using server-side execution of PHP header location redirects, search engines may not follow the redirect properly, leading to potential indexing issues. To ensure proper indexing, use a 301 redirect instead of a PHP header location redirect. This will inform search engines that the content has permanently moved to a new location.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.example.com/new-page");
exit();
?>