重定向页面后如何保存HTML文件

I am trying to save a HTML page after redirecting to a new url. The redirection works fine but it seems after redirecting nothing else works in my php script.

I am using CURL to pretend running from a browser where I get the 302 error to redirect to the page. All I need is to save the HTML page content automatically after redirecting.

Any advices are welcome.

$new_url =  'www.example.com';
$path = 'C:/page.html';

// redirect to new pages
header('Location:'. $new_url);
exit();

// load and save the file
$doc = new DOMDocument();
$doc->loadHTMLFile($new_url);
$doc->saveHTMLFile($path);

Then try save HTML before redirect:

$new_url =  'www.example.com';
$path = 'C:/page.html';

// load and save the file
$doc = new DOMDocument();
$doc->loadHTMLFile($new_url);
$doc->saveHTMLFile($path);

// redirect to new pages
header('Location:'. $new_url);
exit();