简体   繁体   中英

get content of url ignoring redirect with php curl

Is possible ignore a 301 Moved Permanently redirect and get contents of original webpage. Example: I have a domain1.xxx/post1/ and this redirect to domain2.xxx/home/ (but i'm sure that post1 is still prensent in first url) is possible get content of post1 from the domain1.xxx?

<?php 

$url = 'domain1.xxx/post1/'; 
    $ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_HEADER,1); 
curl_setopt($ch, CURLOPT_NOBODY,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //important
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);//important

$r = curl_exec($ch); 
curl_close($ch); 
echo $r;

?>`

But so return me :

"Moved Permanently

The document has moved here."

is a test is not hacking i have a authorization of owner of the site to test this. The site is done with wordpress.

Thnak you

It's entirely unlikely for this to be possible given that it's usually the web server which serves the 301 information and redirects the page (eg a .htaccess file). This means the web server won't look for a web page to serve and thus won't serve up files or data.

In fact, it's likely that the original content doesn't even exist any more, if the owner has already deleted the content (or moved it to the new place).

(I use the word "likely" in this as it really depends on specific server configuration.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM