Если речь идет только о перенаправлении URL-адреса, просмотрите следующий код, я задокументировал его для вас, чтобы вы могли легко и напрямую его использовать, у вас есть два основных параметра cURL, управляющих перенаправлением URL-адреса (CURLOPT_FOLLOWLOCATION / CURLOPT_MAXREDIRS):
// create a new cURL resource
$ch = curl_init();
// The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
// The contents of the "User-Agent: " header to be used in a HTTP request.
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0");
// TRUE to include the header in the output.
curl_setopt($ch, CURLOPT_HEADER, false);
// TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
// grab URL and pass it to the output variable
$output = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
// Print the output from our variable to the browser
print_r($output);
Приведенный выше код решает проблему перенаправления URL-адреса, но не касается файлов cookie (ваш локальный URL-адрес, похоже, имеет дело с файлами cookie). Если вы хотите иметь дело с файлами cookie с ресурса cURL, то вам, возможно, придется взглянуть на следующие параметры cURL:
CURLOPT_COOKIE
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR
Для получения более подробной информации, пожалуйста, перейдите по следующей ссылке:
http://docs.php.net/function.curl-setopt