I'm using curl to make php send an http request to some website somewhere and have set CURLOPT_FOLLOWLOCATION to 1 so that it follows redirects. How then, can I find out where it was eventually redirected?
To follow redirect with Curl, use the -L or --location command-line option. This flag tells Curl to resend the request to the new address. When you send a POST request, and the server responds with one of the codes 301, 302, or 303, Curl will make the subsequent request using the GET method.
Right-click on the page that is generating the redirect and choose "Inspect Element." Chrome opens a pane at the bottom of the browser window that shows all of the HTML code from the site. Scroll up to "<head>" in the Element Inspector and click the arrow next to it to expand the information.
Simply head to Analytics and follow this path: HTTP Codes, Top Charts, HTTP Status Codes Distribution or Insights, and then click 301 URLs in the pie chart. There are also a variety of other ways you can navigate to your 301s within Analytics and URL Explorer.
You can do something like:
curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // returns the last effective URL
$ch = curl_init( "http://websitethatredirects.com" );
$curlParams = array(
CURLOPT_FOLLOWLOCATION => true,
);
curl_setopt_array( $ch, $curlParams );
$ret = curl_exec( $ch );
$info = curl_getinfo( $ch );
print $info['url'];
This will show you the URL that you were ultimately redirected to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With