Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: 302 temporary redirect issue

Status Resolved
Add-on / Version Publisher
Severity Trivial
EE Version

Tom Goethals

Apr 24, 2013

Hi Brian,

i’m trying to parse some pages serverside to build a list of assets to cache in an app.

when the serverside script using file_get_contents tries loading a url with a language that is not my default language it results in a “to many redirects error”.

Using Charles (web debugging proxy) i can sometimes see the “non default language” pages return a 302 header to the same location, and even sometimes to a different location, adding index.php to the url.

any thoughts on how i would go around fixing this? or where to start looking?

Thx already,
Tom

#1

BoldMinded (Brian)

Hi Tom. Are you using the language prefix setting? What about the force prefix setting? If so, try turning them off and see what happens.

#2

BoldMinded (Brian)

Have you tried CURL instead? I believe it has a setting to ignore redirects… its a bit more powerful that file_get_contents().

#3

Tom Goethals

Yes i tried curl, are you referring to the option CURLOPT_FOLLOWLOCATION When i set it to true, i get empty $content, to false i get the redirect notice ‘Document Moved’

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_MAXCONNECTS => 2,

CURLOPT_HEADER => false, CURLOPT_VERBOSE => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CLOSEPOLICY => CURLCLOSEPOLICY_OLDEST )); $contents = curl_exec($curl);

#4

Tom Goethals

I am using the language prefix, i’m pretty sure that is what is causing it to happen. Will have to change quite some stuff to just use the cookie instead of the language prefix.

Changing the force prefix param does not make a difference.

#5

BoldMinded (Brian)

If you hit the URL directly with the language prefix in it, then it shouldn’t be redirecting. It should only redirect when you change languages or if force prefix is on but isn’t found in the URL.

#6

Tom Goethals

thought so to.. also that is what i’m finding in Charles. but for some reason, CURL still gets redirects.

// this code

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_MAXCONNECTS => 2,

CURLOPT_HEADER => false, CURLOPT_VERBOSE => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_CLOSEPOLICY => CURLCLOSEPOLICY_OLDEST )); //echo curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);

$contents = curl_exec($curl); curl_close($curl);

echo $url . “\n”; echo $contents;

// returns this output

http://productexplorer.butspace.com/index.php/nl/content/gearbox <head><title>Document Moved</title></head> <body><h1>Object Moved</h1>This document may be found here</body>

// the redirect points to the exact same url… // might updating to the latest version of publisher help with this? (don’t want to mess up anything else 😊

#7

Arne Van den Bogaert

    $cookie_file = "cookie1.txt";    

    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_COOKIESESSION => true,
    CURLOPT_COOKIEFILE => $cookie_file,
    CURLOPT_COOKIEJAR => $cookie_file,

Fixed our problem, because the redirect sends a cookie when requesting a language other than the default one!

#8

Tom Goethals

Thx Arne and Brian, this ticket can be closed now 😊

#9

BoldMinded (Brian)

Glad you guys figured it out! Thanks for the info, will keep it in mind if this comes up again.

Login to reply