[Chicago-talk] Generate a 404 error from a perl script

Don Drake don at drakeconsulting.com
Wed Dec 23 10:51:36 PST 2015

Take a look at this example:

http://www.oreilly.com/openbook/cgi/ch03_07.html <http://www.oreilly.com/openbook/cgi/ch03_07.html>

$remote_host = $ENV{'REMOTE_HOST'};
print "Content-type: text/plain", "\n";
if ($remote_host eq "bu.edu") {
        print "Status: 200 OK", "\n\n";
        print "Great! You are from Boston University!", "\n";
} else {
        print "Status: 400 Bad Request", "\n\n";
        print "Sorry! You need to access this from Boston University!", "\n";
exit (0);


Don Drake

> On Dec 23, 2015, at 11:43 AM, Jim Jacobus <JJacobus at PonyX.com> wrote:
> How to I create a 404 error from a cgi-bin script. I know the message needs to be before any other text, but I'm having trouble with this.
> Background: I have a script that is indexed by all the search engines. It has a parameter which is a item number (e.g. http://example.com/cgi-bin/script.pl?nnnnnn ) where nnnnnn is a item number. The script figures out if this is a current item number and forwards it to an HTML page if it is. If it isn't a current item number, I create a page that is a similar product. The item numbers (nnnnnn) are added and deleted all the time. I want the search engines to stop indexing expired items, so I want to create a 404 error but still produce a page for the end user.
> I thought there was a simple print statement I needed to write out, but I'm having trouble figuring out what it is.
> Thanks in advance.
> Jim
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20151223/943f9331/attachment.html>

More information about the Chicago-talk mailing list