What are some best practices for handling URL redirection in PHP?

When handling URL redirection in PHP, it is important to ensure that the redirection is done correctly to avoid potential security risks such as open redirects or infinite loops. One best practice is to use the header() function to send a Location header with the new URL for redirection.

// Redirect to a new URL
header("Location: https://www.example.com/new-page.php");
exit();