title: php curl - follow relative paths
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6615971/is-it-possible-to-use-curl-with-relative-path-in-php">Is it possible to use curl with relative path in PHP?</a>  </p>
  </blockquote>
  
  
  
  <p>I have been trying for hours to get a script to work that will follow relative urls.</p>
  
  <p>A quick summary of the problem.</p>
  
  <p>I'm using the <code>FOLLOWLOCATION</code> option to follow URLs, but when the url is:</p>
  
  <pre><code>/redirectPage.html
  </code></pre>
  
  <p>curl follows it like this:</p>
  
  <pre><code>localhost/redirectPage.html
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>$ch = curl_init();
  
  //set options
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  curl_setopt($ch, CURLOPT_REFERER, $referer);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  
  
  $content = curl_exec($ch);
  
  
  curl_close($ch);
  </code></pre>
  
  <p>The few "solutions" I've found involve parsing the DOM Document and replacing the href attributes with the absolute URL, but I'm looking for a solution that will allow me to still use <code>FOLLOWLOCATION</code>. Is there a way to set a base URL in curl, or capture the redirected url that is followed in the <code>FOLLOWLOCATION</code> option and append a string to it?</p>
  
  <p>Please help.</p>