Are there any best practices to follow when implementing a URL redirection in PHP?

When implementing URL redirection in PHP, it is important to ensure that the redirection is done correctly to avoid any potential security risks. One best practice is to use the header() function to send a raw HTTP header for the redirection. Additionally, it is recommended to include an exit() function after the header() function to prevent any further code execution.

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