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.


In reply to Re^4: (OT) cgi: relative v. absolute paths, Apache by 7stud
in thread (OT) cgi: relative v. absolute paths, Apache by 7stud

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.