What are the best practices for creating a PHP script for URL redirection?

When creating a PHP script for URL redirection, it is important to ensure that the redirection is done securely and efficiently. One best practice is to use the header() function in PHP to send a raw HTTP header for the redirection. This ensures that the redirection happens at the server level and not just on the client side.

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