I'm trying to get page content by URL (e.g. 'http://example.com/page.html
') using PHP, but remote server redirects it to another page (e.g. 'http://example.com/another-page.html
') and when I try to execute code:
$p = file_get_contents('http://example.com/page.html');
echo $p;
browser returns 404 error:
The requested URL /another-page.html was not found on this server.
As I understand, instead of getting 'http://example.com/another-page.html
', PHP tries to return 'another-page.html' from my localhost and of course there is no such page. Seems like remote server redirects using local address ('/another-page.html
' instead of 'http://example.com/another-page.html
') which is correct of course, but I don't know how to deal with it.
Could anybody advise me, how could I solve this problem?
Thanks in advance