How can domains be redirected to different servers using PHP?

To redirect domains to different servers using PHP, you can use the header() function to send a 301 or 302 HTTP status code along with the new location URL. This will instruct the browser to redirect to the specified server.

<?php
$newServer = "https://www.newserver.com";
header("Location: $newServer", true, 301);
exit();
?>