httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Turner <>
Subject Re: [users@httpd] ErrorDocument initiated from a CGI program
Date Sat, 29 Mar 2003 04:20:08 GMT
Jack Roth wrote:

>> From: Gary Turner []
>>> Jack Roth wrote:
>> Do you want the script to *generate* an error, or deliver an error
>> message?
>We want the script to generate an error which is caught by the

You may be fixating on the means, and ignoring alternatives.  The errors
you want to deal with, as I understand, are not Apache errors, but are
interactive/backend limitations.  True?  In that case, do not worry
about http error codes.  Use cgi scripts, maybe combined with SSI to
present custom informational messages.
>ErrorDocument 404 "this is from httpd"
>And the script causes an error 404, then the URLs
>http://myserver/DoesNotExist and
>both result in a "this is from httpd" message.
>> print "content-type: text/html\n\n";
>> print "Status:  404 could not fulfill your request\n";
>Unless I've done something wrong, the above script generates a web page
>containing "Status: 404 could not fulfill your request" not "this is
>from httpd". 

This is a simple print statement.  Change it as you wish, eg.

	print "Roses are red,\nViolets are blue,\n";
	print "Don't look now,\nBut you made a boo-boo\n";

It does not generate an actual error nor call Apache's built in error

>We are currently delivering a static error message from our C++ CGI
>program, but our VARs would like to be able to customize the error
>message or in some cases run another program to process the error. The
>ErrorDocument feature seems perfect for this.

>> If you want the script to generate an actual error, use this:
>> #!/usr/bin/perl -wT
>> use strict;
>> print "Location: http://localhost/nofile\n\n";
>> The above assumes that "nofile" does not exist in the DocumentRoot.
>This works for error 404's, how about generating an arbitrary error
>number, like 500, 503?

If you have a *real* http error, such as the 500 errors you were
getting, you don't need to go out of your way to generate one <grin>,
and you can use the ErrorDocument lines to customize as desired.  OTOH,
you can use the "Location" directive to send the client to whichever
customized error page you or your customers desire.  An if, elif, endif
chain will handle the decision making (or in C++, a case statement).
The $SERVER_NAME environmental variable should come in handy.

The advice is free, and worth every cent.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message