This is a discussion on Why does this relative file path work? within the Linux Web Servers forums, part of the Web Server and Related Forums category; On a shared Linux/Apache host, my directory structure is as follows: home data HTML cgi topic downloads topic contains ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On a shared Linux/Apache host, my directory structure is as follows:
home data HTML cgi topic downloads topic contains page.html (and also the "downloads" directory). page.html contains a link to cgi/script.pl. script.pl increments a count in a data file and then redirects the client to download a file: $k_counts_filepath = "../../data/hes_dl_counts.txt"; $k_target_dir_uri = "../../topic/downloads/"; # code to validate existence of download target and to increment counter goes here if ($ok) { print "Location: $k_target_dir_uri$targetname\n"; print "Status: 302 Found\n\n"; } else { print "Status: 404 Not found\n\n"; } The double-up (../..) in the path to the file in the "data" directory seems straightforward; it's relative to the cgi directory which contains the script. But notice the ../.. in the path to the "downloads" directory. Wanting to use a relative rather than absolute path I arrived at this by trial and error, but I don't understand why it works. What is the base directory that the "../.." is being applied to? -- For mail, please use my surname where indicated: steve@surname.reno.nv.us (Steve Brecher) |
|
|||
|
On Fri, 4 Jul 2003, Steve Brecher <see@my.signature.at.end> wrote:
> On a shared Linux/Apache host, my directory structure is as follows: > > home > data > HTML > cgi > topic > downloads > > topic contains page.html (and also the "downloads" directory). page.html > contains a link to cgi/script.pl. script.pl increments a count in a data > file and then redirects the client to download a file: > > $k_counts_filepath = "../../data/hes_dl_counts.txt"; > $k_target_dir_uri = "../../topic/downloads/"; > # code to validate existence of download target and to increment counter > goes here > if ($ok) { > print "Location: $k_target_dir_uri$targetname\n"; > print "Status: 302 Found\n\n"; } > else { > print "Status: 404 Not found\n\n"; } > > The double-up (../..) in the path to the file in the "data" directory seems > straightforward; it's relative to the cgi directory which contains the > script. > > But notice the ../.. in the path to the "downloads" directory. Wanting to > use a relative rather than absolute path I arrived at this by trial and > error, but I don't understand why it works. What is the base directory that > the "../.." is being applied to? You do not need a Status: header for a redirect (apache does that automatically for Location:). You have one too many "../" in there. If this was a /~user/ URL it would not work. But apparently you have a virtual host and a URI path cannot go above the root of your website, so from cgi dir, the following should all end up in the same place: /topic/downloads/ (full URI path) .../topic/downloads/ (relative path, did this not work?) .../../topic/downloads/ (backtracking above URI root ignored) I don't know whether apache or the browser generated the proper path for the redirect. But the browser needs to construct a full URL path for an HTTP request and it cannot go above URI root. If something did not work with the actual relative path, either you made a typo or there is something unusual about your server config that we cannot see here. -- David Efflandt - All spam ignored http://www.de-srv.com/ http://www.autox.chicago.il.us/ http://www.berniesfloral.net/ http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/ |
|
|||
|
"David Efflandt" <efflandt@xnet.com> wrote:
> On Fri, 4 Jul 2003, Steve Brecher <see@my.signature.at.end> wrote: > > On a shared Linux/Apache host, my directory structure is as follows: > > > > home > > data > > HTML > > cgi > > topic > > downloads > > > > topic contains page.html (and also the "downloads" directory). page.html > > contains a link to cgi/script.pl. script.pl increments a count in a data > > file and then redirects the client to download a file: > > > > $k_counts_filepath = "../../data/hes_dl_counts.txt"; > > $k_target_dir_uri = "../../topic/downloads/"; > > # code to validate existence of download target and to increment counter > > goes here > > if ($ok) { > > print "Location: $k_target_dir_uri$targetname\n"; > > print "Status: 302 Found\n\n"; } > > else { > > print "Status: 404 Not found\n\n"; } > > > > The double-up (../..) in the path to the file in the "data" directory seems > > straightforward; it's relative to the cgi directory which contains the > > script. > > > > But notice the ../.. in the path to the "downloads" directory. Wanting to > > use a relative rather than absolute path I arrived at this by trial and > > error, but I don't understand why it works. What is the base directory that > > the "../.." is being applied to? > > You do not need a Status: header for a redirect (apache does that > automatically for Location:). Noted. > You have one too many "../" in there. If this was a /~user/ URL it would > not work. But apparently you have a virtual host and a URI path cannot go > above the root of your website, so from cgi dir, the following should all > end up in the same place: > > /topic/downloads/ (full URI path) > ../topic/downloads/ (relative path, did this not work?) (This is now irrelevant because I am persuaded that what is needed to comply with CGI best practice is either an entire URL or a complete path; however, for the record...) It didn't work; the server reported that the URL /~myaccount/cgi/topic/downloads/target.file was not found on the server. > ../../topic/downloads/ (backtracking above URI root ignored) As noted originally, this worked. -- For mail, please use my surname where indicated: steve@surname.reno.nv.us (Steve Brecher) |
| Thread Tools | |
| Display Modes | |
|
|