Why does this relative file path work?

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 ...


Go Back   Usenet Forums > Web Server and Related Forums > Linux Web Servers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-04-2003
Steve Brecher
 
Posts: n/a
Default Why does this relative file path work?

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)


  #2 (permalink)  
Old 07-05-2003
David Efflandt
 
Posts: n/a
Default Re: Why does this relative file path work?

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/
  #3 (permalink)  
Old 07-05-2003
Steve Brecher
 
Posts: n/a
Default Re: Why does this relative file path work?

"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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:37 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0