Re: Serving default error pages after CGI?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 13, 2009 at 7:21 AM, Eric Covener <covener@xxxxxxxxx> wrote:
> On Tue, Jan 13, 2009 at 7:11 AM, Sacha Varma <sacha@xxxxxxxxx> wrote:
>> I've been unable to google up the answer to this, so if anyone can help it
>> would be much appreciated.
>>
>> The CGI standard (RFC 3875, 6.3.3) allows a CGI script to output an HTTP
>> status code header (e.g. 'Status: 404 Not Found'). A response body is
>> optional.
>>
>> My CGI program outputs just this status header in certain situations, with
>> no body, and I would like Apache to serve the configured ErrorDocument when
>> this happens. It is relaying the HTTP status correctly, but at the moment it
>> seems to serve the CGI response's body, whether or not there is one, rather
>> than falling through to error handling. In other words, I see an empty
>> response, rather than the usual Apache 404 page.
>>
>> Is there a simple way to change this behaviour?
>>
>> 2.0.53 is what I've been developing with, if that's relevant.
>
> Generally, Apache only uses an ErrorDocument when the status code is
> set by the Apache module, not just when it's forwarded by some other
> application/server. Internally, the status code for the response is
> separate from the "return code" for the handler -- ErrroDocuments are
> related to the return codes for the handler itself.
>
> --
> Eric Covener
> covener@xxxxxxxxx

You could use your CGI script to fetch the body of the error doc you
want to use. If your error doc is more complex than straight HTML
(MultiViews, SSI, or if the error doc is itself a CGI script, for
instance), then you could use your CGI to fetch it from your apache
server as a client and serve up the response. Depending on your cgi
language, it might have built in support for sockets or even high
level API's (e.g., php and python, I believe, both have support for
fetching web pages). If it's a shell script, I'm sure there are
non-interactive alternatives to telnet you can use. Once you're
connected, you just have to fetch an address that you know will give
the error doc you're looking for. You should be able to set up come
canonical URLs for each type of error using mod_rewrite, and the R
flag, I think. For instance:

RewriteEngine on
RewriteRule ^/FORCE_ERROR_404    /    [R=404]
RewriteRule ^/FORCE_ERROR_500    /    [R=500]
#etc...

With those rules, if you fetch http://yoursever.com/FORCE_ERROR_404,
it should give you the error doc for 404 errors. *I think*. I'm not at
a server so I can't test it. If that doesn't work, then you can just
be creative about fetching the error docs from the server. For
instance, set aside a URL that will never have content and fetch that
for 404. Set up a CGI script that will always fail and fetch that to
get 500 errors, etc.

Hope that helps.
-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux