How can PHP developers effectively communicate URL changes to search engines like Google to prevent indexing of outdated URLs?
When URLs on a website are changed, it is important to communicate these changes to search engines like Google to prevent indexing of outdated URLs. One effective way to do this is by using the PHP header function to send a 301 redirect status code to inform search engines that the URL has permanently moved to a new location.
<?php
// Redirect to the new URL with a 301 status code
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/new-url");
exit();
?>