curl-library
Re: relative url to absolute
Date: Mon, 25 Feb 2008 10:25:55 -0500
--On Saturday, February 23, 2008 4:31 PM +0100 klabautermack
<0klabautermack_at_gmx.de> wrote:
> Hi,
>
> i want to build urls from relative urls found in the parsed html file and
> the url given by
>
> curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
>
> problem:
> how to detect if "url" is a directory or a file?
> example:
> http://xyz.com/hans.php/index.html
> is a valid url and i can get http://xyz.com/hans.php from
> curl_easy_getinfo(..). i dont know, if http://xyz.com/hans.php is a path
> to the file hans.php or a path to the directory http://xyz.com/hans.php/
> with the file index.html.
>
> my current solution:
>
> append '/' to http://xyz.com/hans.php.
>
> connect http://xyz.com/hans.php/ with
> curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
>
> if response code is 200, hans.php cant be a file, and i can use
> http://xyz.com/hans.php/ to build the absolute urls.
>
> is there any other solution without two connections?
>
> Thank you for your help,
>
> regards
> Hans
The formal spec for handling relative urls is
<http://www.faqs.org/rfcs/rfc1808.html>. In particular section 4 details
resolving relative urls.
Nathan Moore
Received on 2008-02-25