Sending back 404 error

Discussion in 'Perl Misc' started by Winston Kotzan, May 24, 2004.

  1. Hi,

    I have a Perl script that creates dynamic pages using a passed page
    variable. If someone tries to access a page that does not exist, I want my
    script to send back a custom 404 error. The problem is that I want to make
    sure the HTTP 404 status code is sent back to the browser, and not just an
    HTTP 200 response with a page displaying an error. The reason is that I
    want to see the 404 status code in my Apache server logs. What command can
    I use to send the correct HTTP status code?

    Thanks.

    --
    Winston Kotzan
    http://www.wakproductions.com/
     
    Winston Kotzan, May 24, 2004
    #1
    1. Advertising

  2. Winston Kotzan wrote:
    > I have a Perl script that creates dynamic pages using a passed page
    > variable. If someone tries to access a page that does not exist,
    > I want my script to send back a custom 404 error. The problem is
    > that I want to make sure the HTTP 404 status code is sent back to
    > the browser, and not just an HTTP 200 response with a page
    > displaying an error. The reason is that I want to see the 404
    > status code in my Apache server logs. What command can I use to
    > send the correct HTTP status code?


    print "Content-Type: text/html; charset=iso-8859-1\n";
    print "Status: 404 Not Found\n" if [not exist];
    print "\n";

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, May 24, 2004
    #2
    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. Jonathan Folland
    Replies:
    2
    Views:
    1,672
    Jonathan Folland
    Mar 17, 2005
  2. Replies:
    3
    Views:
    1,008
    HalcyonWild
    Oct 14, 2005
  3. Bishop
    Replies:
    1
    Views:
    819
    Bishop
    Feb 24, 2007
  4. Replies:
    0
    Views:
    442
  5. Andy B.
    Replies:
    0
    Views:
    468
    Andy B.
    Dec 23, 2008
Loading...

Share This Page