What are the best practices for handling URL redirection in PHP?
When handling URL redirection in PHP, it is important to ensure that the redirection is done securely and efficiently. One common practice is to use the header() function to send a 301 or 302 HTTP status code along with the new URL. This helps search engines understand that the old URL has permanently or temporarily moved to a new location.
<?php
// Redirect to a new URL with a 301 status code
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newurl.com");
exit();
?>