redirect using location header does not work from an already redirected doc.

Discussion in 'Perl Misc' started by Will, Nov 30, 2003.

  1. Will

    Will Guest

    interesting situation:


    OS: Windows
    Server: Apache 1.3.29

    Modified ErrorDocument 404 to point to a redirect.pl script in cgi-bin
    http.conf
    ErrorDocument 404 /cgi-bin/redirect.pl

    redirect.pl
    sub DO_REDIRECT {
    ...

    print "Location: /index.html \n\n";

    ...
    }

    this works when I access the script directly by its url.
    but when its forwarded to by the 404 error it does not work.

    Any one has any idea how to make it work, please reply.



    Additional Info ... :
    I tried printing out the headers manually but it does not work.

    lets say: http://yourdomain.com/some_nonsensical_stuff_here



    Here are some headers from the 404 redirect:

    GET /some_nonsensical_stuff_here HTTP/1.1
    -server headers-
    HTTP/1.z 404 Not Found
    Server: Apache/1.3.29 (Win32)
    Location: http://yourdomain.com/index.html
    Keep-Alive: timeout=15, max=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/plain

    The header from accessing the url directly are a bit different:

    GET /index.html HTTP/1.1
    -server headers-
    HTTP/1.z 200 OK
    Server: Apache/1.3.29 (Win32)
    Etag: "0-5d6-3af1f126"
    Accept-Ranges: bytes
    Content-Length: 1494
    Content-Type: text/html
    Will, Nov 30, 2003
    #1
    1. Advertising

  2. Re: redirect using location header does not work from an alreadyredirected doc.

    Please note that your question is totally off topic in this group.

    Will wrote:
    >
    > redirect.pl
    > sub DO_REDIRECT {
    > ...
    > print "Location: /index.html \n\n";
    > ...
    > }
    >
    > this works when I access the script directly by its url.
    > but when its forwarded to by the 404 error it does not work.


    I would try the full URL instead of just /index.html.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Nov 30, 2003
    #2
    1. Advertising

  3. Re: redirect using location header does not work from an alreadyredirected doc.

    On Sun, 29 Nov 2003, Will wrote:

    > interesting situation:


    Would be on-topic for comp.infosystems.www.authoring.cgi

    > print "Location: /index.html \n\n";


    Check the CGI specification. That form of CGI response is mandated to
    return its results with status 200 (sometimes known as an internal
    redirection).

    To get a redirection by means of an external HTTP redirection
    transaction (HTTP status 30x and HTTP location header), the CGI
    specification calls for a complete URL in the CGI Location: response.

    > Any one has any idea how to make it work, please reply.


    Perlfaq9 points you at appropriate resources (and the appropriate
    newsgroup for discussing the topic). Use the FAQs, Luke.
    Alan J. Flavell, Nov 30, 2003
    #3
  4. Will

    Will Guest

    Using full url, does not work either.
    The redirect script works fine if it is not forwarded to by ErrorDocument 404

    I think the problem is in that the page already has header
    HTTP/1.z 404 Not Found

    I tried overwriting that but so far no luck.
    I've read up on perlfaq9 and other, so far no clue.

    What group should I post it in?
    It seems like since I am writing it in perl: comp.lang.perl.misc
    Will, Dec 2, 2003
    #4
  5. Will

    Will Guest

    > Check the CGI specification. That form of CGI response is mandated to
    > return its results with status 200 (sometimes known as an internal
    > redirection).


    yes, but if the script is pointed to by ErrorDocument 404 the header
    is 404.

    >
    > To get a redirection by means of an external HTTP redirection
    > transaction (HTTP status 30x and HTTP location header), the CGI
    > specification calls for a complete URL in the CGI Location: response.
    >


    I tried adding an addition header 30x or 200 along with location
    header but it just does not work. My guess would be I would have to
    modify the original top
    HTTP/1.z 404 Not Found header. I am not really sure how.

    >
    > Perlfaq9 points you at appropriate resources (and the appropriate
    > newsgroup for discussing the topic). Use the FAQs, Luke.


    Read them all before, can not find a solution yet.

    Where would I post this. this is a perl group.
    Will, Dec 2, 2003
    #5
  6. Re: redirect using location header does not work from an alreadyredirected doc.

    On Tue, 1 Dec 2003, Will wrote:

    > > Check the CGI specification. That form of CGI response is mandated to
    > > return its results with status 200 (sometimes known as an internal
    > > redirection).

    >
    > yes, but if the script is pointed to by ErrorDocument 404 the header
    > is 404.


    I'd overlooked that detail of the original problem, yes. Sorry.

    An external redirection will still need status 30x, though.

    > I tried adding an addition header 30x or 200 along with location
    > header but it just does not work.


    That looks like a classic case of what the posting guidelines warn
    against. You haven't said precisely what you did, and you haven't
    said precisely what you hoped would happen, and you haven't said what
    you found did happen. "it just does not work" sets off all the alarm
    bells here.

    [detail omitted]

    > > Perlfaq9 points you at appropriate resources (and the appropriate
    > > newsgroup for discussing the topic). Use the FAQs, Luke.

    >
    > Read them all before, can not find a solution yet.
    >
    > Where would I post this.


    On the group suggested by perlfaq9 (if you can get past the group's
    automoderation bot).

    Or maybe on the relevant comp.infosystems.www.servers.* group, if this
    is in fact an issue with the ErrorDocument configuration rather than
    being a specifically CGI issue.

    > this is a perl group.


    Yes.
    Alan J. Flavell, Dec 2, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    498
    Tor Iver Wilhelmsen
    Sep 17, 2004
  2. Replies:
    1
    Views:
    390
  3. Roedy Green
    Replies:
    4
    Views:
    886
    Roedy Green
    Nov 17, 2010
  4. Jiong Feng
    Replies:
    9
    Views:
    1,361
    Lasse Reichstein Nielsen
    Jun 24, 2004
  5. Replies:
    5
    Views:
    154
    Randy Webb
    May 25, 2005
Loading...

Share This Page