I'm doing some requests to an API via WordPress, and the API uses SSL connections if they're turned on in the API settings. I'd like to determine whether SSL is turned on or off without having to ask the user if SSL is turned on on their account, and the API does a good job at redirecting, meaning

Now what I'd like to do is see whether a redirect happened or not and record that to my options so that the other requests are fired to the correct URL without any redirections.

So my question is: is there a way to determine the final destination after firing a WP_Http->request() when the request is being redirected?

I can't see any info about that in the response arrays, I only get to see the final response but I have no idea what URL that came from. What I can do is set the redirection parameter to 0 and catch the max redirects allowed error, but that's not bullet-proof, since I still don't know whether the redirect happened from http to https or simply another page under http.

I hope this all makes sense, let me know if you have any ideas.


~ K

2 Answers 2


You can use wp_remote_head() request for a test, it should get you response code and redirect target.

  • 1
    What if there are three redirects, do you suggest looping?
    – kovshenin
    Apr 29, 2011 at 17:05
  • @kovshenin yep, I don't see other way. Redirection is probably handled differently in different transports and it's also likely recursive... It is easier to just setup test case with HEAD if you need this once to save result.
    – Rarst
    Apr 29, 2011 at 17:28

Rarst is right. This works...

$result = wp_remote_head( $your_url, $your_args );
echo $result['headers']['location'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.