In terms of SEO, what are the best practices for implementing 301 redirects in PHP to maintain search engine friendliness?

When implementing 301 redirects in PHP to maintain search engine friendliness, it is important to redirect old URLs to new ones to preserve SEO value and prevent broken links. To achieve this, you can use the header() function in PHP to send a 301 redirect header to the browser.

<?php
// Redirect old URL to new URL with a 301 status code
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newurl.com");
exit();
?>