redirection using Location: in Perl CGI script 
Author Message
 redirection using Location: in Perl CGI script

Can the Location: header attribute be used to redirect with a relative path?
I haven't been able to get this to work.
What I'm trying to do is redirect the user to another webpage in the same
directory as the CGI script...

The following works fine: (fully specified URL)

print "Location: http://someserver/somepage/index2.html\n\n"; ### Redirect

but these other ways seem to choke...Is there a way to use a relative path?

print "Location: index2.html\n\n"; ### try to do relative
print "Location: ./index2.html\n\n"; ### another attempt (1 dot)
print "Location: ../index2.html\n\n"; ### yet another attempt (2 dots)

(maybe if this won't work, someone could suggest another method to
accomplish same?)

Thanks much,

Colin



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script

Quote:

> The following works fine: (fully specified URL)

> print "Location: http://someserver/somepage/index2.html\n\n"; ###
Redirect

Here you're printing a whole url which your browser will interpret as a
link because it starts with "http://".

Quote:
> but these other ways seem to choke...Is there a way to use a relative
path?

> print "Location: index2.html\n\n"; ### try to do relative
> print "Location: ./index2.html\n\n"; ### another attempt (1 dot)
> print "Location: ../index2.html\n\n"; ### yet another attempt (2 dots)

Here you are just typing some text, your browser has no way to know
that this is a file name.

You need to use an html tag like "Location: <a href=index2.html>name of
link</a>
to force the filename to treated as a link.

This is an HTML question not a perl question.  Read an HTML book.

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script

Quote:
>> On Mon, 03 Jul 2000 19:26:36 GMT,


>>  The following works fine: (fully specified URL)

>> print "Location:
>> http://someserver/somepage/index2.html\n\n"; ###
> Redirect

> Here you're printing a whole url which your browser will
> interpret as a link because it starts with "http://".

nope.  You are confusing HTML and HTTP.

Quote:
>> but these other ways seem to choke...Is there a way to
>> use a relative
> path?
>>  print "Location: index2.html\n\n"; ### try to do
>> relative print "Location: ./index2.html\n\n"; ###
>> another attempt (1 dot) print "Location:
>> ../index2.html\n\n"; ### yet another attempt (2 dots)

> Here you are just typing some text, your browser has no
> way to know that this is a file name.

nope.  The client can have *no* reliable way of knowing
the underlying representation of a remote object.

Quote:
> You need to use an html tag like "Location: <a
> href=index2.html>name of link</a> to force the filename
> to treated as a link.

nope.  You are confusing HTML and HTTP.

You didn't test this did you?  (Cardinal sin)

Quote:
> This is an HTML question not a perl question.  Read an
> HTML book.

Use the CGI module's self_url() method to work out the
absolute URL referencing this program.  Then use
redirect() with the appropriate URL you constructed.

CGI.pm, q.v.

hth
t
--
"With $10,000, we'd be millionaires!"
                                           Homer Simpson



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script

Quote:

>Can the Location: header attribute be used to redirect with a relative path?
>I haven't been able to get this to work.
>What I'm trying to do is redirect the user to another webpage in the same
>directory as the CGI script...

>The following works fine: (fully specified URL)

>print "Location: http://someserver/somepage/index2.html\n\n"; ### Redirect

Your question is less of a Perl question and more of a HTTP question, I
believe.  Nonetheless Perl has an answer...

From 'perldoc CGI':

       One hint I can offer is that relative links may not work
       correctly when you generate a redirection to another docu-
       ment on your site.  This is due to a well-intentioned
       optimization that some servers use.  The solution to this
       is to use the full URL (including the http: part) of the
       document you are redirecting to.

--
John Borwick



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script

In fact, posted several times to at least two separate groups

Quote:
> > print "Location: index2.html\n\n"; ### try to do relative
> > print "Location: ./index2.html\n\n"; ### another attempt (1 dot)
> > print "Location: ../index2.html\n\n"; ### yet another attempt (2 dots)

> Here you are just typing some text, your browser has no way to know
> that this is a file name.

So you haven't much of a clue either.

I suppose neither of you considered reading the CGI spec?

Quote:
> You need to use an html tag like "Location: <a href=index2.html>name of
> link</a>
> to force the filename to treated as a link.

Like Bu**ery you do.  Sheesh.

Quote:
> This is an HTML question

Nope.  This is a CGI question.

Quote:
> not a perl question.

You got that right.

Once again we see the inadvisability of offering off-topic answers.

f'ups redirected to the appropriate place, where I already posted
my answer to the same (multiposted) question.

Both scores adjusted accordingly.  Good luck.



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script

Quote:
>  Nonetheless Perl has an answer...

One which is unfortunately unsupported by the available interworking
specification.

Quote:
> From 'perldoc CGI':

Documentation bug already reported...

Quote:
>        One hint I can offer is that relative links may not work

There are two kinds of Location: CGI response codified in the CGI
specification.  Neither of them are relative links.

So indeed they "may not work", but that's because the spec doesn't
allow them.

Quote:
>        correctly when you generate a redirection to another docu-
>        ment on your site.  This is due to a well-intentioned
>        optimization that some servers use.

The behaviour in response to the two different kinds of Location: CGI
response is mandated by the specification.  No optimisation is
allowed.  But, as I say, neither kind is relative.

Quote:
> The solution to this
>        is to use the full URL (including the http: part) of the
>        document you are redirecting to.

No.  Both kinds of CGI response codified in the specification are
valid and produce the different effects described in the
specification, on any conforming server.  Each of the two kinds of
response is useful in appropriate situations.

But _relative_ URLs, as opposed to absolute URLpaths, are invalid in a
CGI response. At any rate, this is clear from the draft RFC; the old
NCSA specification is a bit too vague to be unambiguously clear on
this point, and the Perl FAQ and CGI spec may well have been worded at
an earlier time when the situation was still indistinct.



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script


Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script

Quote:

> > From 'perldoc CGI':

> Documentation bug already reported...

That was a late-night mistake, sorry.  The documentation bug that I
previously reported was to the corresponding statement in the Perl
FAQs.  But the item under discussion wasn't the Perl FAQ, it was the
version of the CGI.pm documentation that appears in perldoc in the
distribution.  And this general issue (rather than the specific
technical topic) prompts me to open a new subthread, cc: to Lincoln
Stein.

I've discussed before with Lincoln Stein some of the text of the
CGI.PM POD documentation.  The problem seems to be that the good
CGI.pm documentation is maintained in HTML, and this is the
documentation that I would advise CGI.pm users to refer to:
http://stein.cshl.org/WWW/software/CGI/ for the current production
version.  The CGI.pm POD, on the other hand, turns out from time to
time to contain some obsolete stuff and does not receive the same
level of attention re updates.  Unfortunately, it not only gets
distributed as the module documentation in the Perl distribution, it
also gets automatically converted (and somewhat garbled in the
process, AFAICS) to an HTML-ised form that also gets distributed, and
which had me considerably confused until the distinction was pointed
out to me.

This needs some kind of attention, but I don't know what.  Maybe
CGI.pm needs some alternative packaging into the Perl distribution.
Could someone who has links to the Perl porters suggest an appropriate
way to progress this general issue?

It's a pity for this excellent software to be let down by the
distribution of inadequate documentation, when in fact better
documentation is already available (albeit in a different format). It
would seem to me unreasonable to expect the author to maintain two
lots of documentation in parallel.

cheers



Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script


Wed, 18 Jun 1902 08:00:00 GMT  
 redirection using Location: in Perl CGI script


Quote:
> >> On Mon, 03 Jul 2000 19:26:36 GMT,


> >>  The following works fine: (fully specified URL)

> >> print "Location:
> >> http://someserver/somepage/index2.html\n\n"; ###
> > Redirect

> > Here you're printing a whole url which your browser will
> > interpret as a link because it starts with "http://".

> nope.  You are confusing HTML and HTTP.

No actually I just didn't read the whole post.  I just assumed the
original poster was having trouble creating html links and posted a
quick solution.  If I'd bothered to read the whole post I would have
realised.

duly humbled. m:<

Quote:
> >> but these other ways seem to choke...Is there a way to
> >> use a relative
> > path?
> >>  print "Location: index2.html\n\n"; ### try to do
> >> relative print "Location: ./index2.html\n\n"; ###
> >> another attempt (1 dot) print "Location:
> >> ../index2.html\n\n"; ### yet another attempt (2 dots)

> > Here you are just typing some text, your browser has no
> > way to know that this is a file name.

> nope.  The client can have *no* reliable way of knowing
> the underlying representation of a remote object.

> > You need to use an html tag like "Location: <a
> > href=index2.html>name of link</a> to force the filename
> > to treated as a link.

> nope.  You are confusing HTML and HTTP.

> You didn't test this did you?  (Cardinal sin)

> > This is an HTML question not a perl question.  Read an
> > HTML book.

> Use the CGI module's self_url() method to work out the
> absolute URL referencing this program.  Then use
> redirect() with the appropriate URL you constructed.

> CGI.pm, q.v.

> hth
> t
> --
> "With $10,000, we'd be millionaires!"
>                                            Homer Simpson

Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Redirection using location

2. redirection using Location

3. Wierd redirection problem with Location:

4. redirection Location help

5. Wierd redirection problem with Location:

6. Location, Redirection

7. Determining CGI script location

8. Location of a file modifiable by a CGI Script

9. Determing the location of perl in a Perl script

10. Redirection of POST CGI in Perl

11. perl CGI Redirection

12. about redirection in perl CGI

 

 
Powered by phpBB® Forum Software