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

When handling domain redirection in PHP, it is important to use proper HTTP headers to redirect users to the new domain. This can be achieved by using the header() function in PHP to send a "301 Moved Permanently" status code along with the new domain location.

<?php
// Redirect to a new domain
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com");
exit();
?>