$oldHost = $_SERVER['HTTP_HOST']; $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; if($oldHost == 'www.xxx.com'){ header('HTTP/1.1 301 Moved Permanently'); header('Location: https://xxx.com'.$request_uri);// }