What best practices should be followed when redirecting domains to external websites to ensure a seamless user experience?

When redirecting domains to external websites, it is important to ensure a seamless user experience by using a 301 redirect for permanent moves and a 302 redirect for temporary moves. Additionally, it is recommended to include relevant and descriptive anchor text for the redirect link to provide clarity to users. Lastly, always test the redirect to ensure it functions correctly across different devices and browsers.

<?php
$redirect_url = "https://www.externalwebsite.com";
$http_status_code = 301; // Use 301 for permanent moves, 302 for temporary moves

header("Location: $redirect_url", true, $http_status_code);
exit();
?>