On Thu 17 Sep 2009, Andreas Mock wrote: > How can we dynamically create own error documents without using > the lower level mod_perl/apache api? Is there a simple way? > How can we achieve that?
A very simple registry script: #!/usr/bin/perl use strict; my $r=shift; $r->status($r->args); exit; Then you can configure ErrorDocuments, e.g. ErrorDocument 404 http://huhu.com ErrorDocument 500 "dumm gloffe" Now try it out: A 404 will be translated into a redirect: $ curl http://localhost/etest?404 -v * About to connect() to localhost port 80 (#0) * Trying ::1... connected * Connected to localhost (::1) port 80 (#0) > GET /etest?404 HTTP/1.1 > User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0 OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10 > Host: localhost > Accept: */* > < HTTP/1.1 302 Found < Date: Thu, 17 Sep 2009 11:05:19 GMT < Server: Apache/2.2.13 (Unix) proxy_html/3.0.1 mod_ssl/2.2.13 OpenSSL/0.9.8h DAV/2 SVN/1.6.4 mod_apreq2-20090110/2.7.1 mod_perl/2.0.5threading3 Perl/v5.10.0 < Location: http://huhu.com < Content-Length: 199 < Content-Type: text/html; charset=iso-8859-1 < <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>302 Found</title> </head><body> <h1>Found</h1> <p>The document has moved <a href="http://huhu.com">here</a>.</p> </body></html> * Connection #0 to host localhost left intact * Closing connection #0 a 403 sends the normal error page $ curl http://localhost/etest?403 -v * About to connect() to localhost port 80 (#0) * Trying ::1... connected * Connected to localhost (::1) port 80 (#0) > GET /etest?403 HTTP/1.1 > User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0 OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10 > Host: localhost > Accept: */* > < HTTP/1.1 403 Forbidden < Date: Thu, 17 Sep 2009 11:05:58 GMT < Server: Apache/2.2.13 (Unix) proxy_html/3.0.1 mod_ssl/2.2.13 OpenSSL/0.9.8h DAV/2 SVN/1.6.4 mod_apreq2-20090110/2.7.1 mod_perl/2.0.5threading3 Perl/v5.10.0 < Content-Length: 207 < Content-Type: text/html; charset=iso-8859-1 < <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /etest on this server.</p> </body></html> * Connection #0 to host localhost left intact * Closing connection #0 and a 500 delivers a custom error message: $ curl http://localhost/etest?500 -v * About to connect() to localhost port 80 (#0) * Trying ::1... connected * Connected to localhost (::1) port 80 (#0) > GET /etest?500 HTTP/1.1 > User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0 OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10 > Host: localhost > Accept: */* > < HTTP/1.1 500 Internal Server Error < Date: Thu, 17 Sep 2009 11:09:19 GMT < Server: Apache/2.2.13 (Unix) proxy_html/3.0.1 mod_ssl/2.2.13 OpenSSL/0.9.8h DAV/2 SVN/1.6.4 mod_apreq2-20090110/2.7.1 mod_perl/2.0.5threading3 Perl/v5.10.0 < Content-Length: 11 < Connection: close < Content-Type: text/html; charset=iso-8859-1 < * Closing connection #0 dumm gloffe Torsten -- Need professional mod_perl support? Just hire me: torsten.foert...@gmx.net