in reply to Re^3: (OT) cgi: relative v. absolute paths, Apache
in thread (OT) cgi: relative v. absolute paths, Apache

Ok, I think I get it now. Relative paths are resolved based on the directory structure specified in the request url. For instance, suppose you have a web page that is requested using the following url:

www.acme.com/dir1/dir2/page.htm

You can see a directory structure in that url, and that directory structure will be used to turn relative paths into absolute paths. If page.htm contains a link to another page and the link specifies a relative path:

<a href = "../results.htm">click me</a>
then you look at the url in the original request to sort out the path:

www.acme.com/dir1/dir2/page.htm

In this case, the original page.htm is in the directory dir2, which is the current directory. Looking at the request url, the parent directory of dir2 is dir1. Therefore, the browser resolves the relative path:

../results.htm

into the absolute path: www.acme.com/dir1/results.htm

If the href had used the path: ../../dir3/results.htm, then the browser would resolve the relative path into the absolute path:

href = "../../dir3/results.htm" <-----relative path
www.acme.com/dir1/dir2/page.htm <---request url
www.acme.com/dir3/results.htm <----absolute path

In my case, the url that was used to request my cgi script was:

http://localhost/cgi-bin/prog1.pl

The current directory in that url is cgi-bin. So when the perl script produced an <img> tag with the relative path:

<img src="../my_imgs/blue_square.jpg">

the parent directory was localhost. Therefore, the relative url corresponds to the absolute url: localhost/my_imgs/blue_sqare.jpg.

Now it's Apaches turn. Apache maps the host, in this case localhost (in the first example it was www.acme.com), to the htdocs directory. Therefore, the url tells Apache to look for a subdirectory in htdocs called my_imgs and then looks in my_imgs for a file called blue_square.jpg.