http://www.perlmonks.org?node_id=898048


in reply to Re^4: mod_perl give 404 not_found with content
in thread mod_perl give 404 not_found with content

Unfortunately it doesn't work for me.
My mod_perl/startup.pl looks like this:
use strict; use Apache::DBI; use Apache2::Request; use File::Slurp; use Net::SMTP; #use CGI; #CGI->compile(':all'); Apache::DBI->connect_on_init('DBI:mysql:dbname::localhost', "user", "* +*****", { PrintError => 1, # warn() on errors RaiseError => 0, # don't die on error AutoCommit => 1, # commit executes mysql_enable_utf8 => 1, # immediately } ) or die "Cannot connect to database: $DBI::errstr";
And then there's a myscript.pl in the mode_perl dir that looks like this:
#!/usr/bin/perl use strict; use warnings; my $r = shift; my $cgi = Apache2::Request->new($r); my $QUERY; if ($cgi->param('q') =~ /^([a-zA-Z0-9\ \.\,\-_\:\;]+)$/) { $QUERY = $1; } my $ruri = $ENV{'REQUEST_URI'}; $ruri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; ... ... if ($sth->rows == 0) { #$r->err_headers_out->set(Location => "$ruri/"); $r->status(404); #$r->status(Apache2::Const::NOT_FOUND); $r->content_type('text/html'); $r->print(<<"END"); <html> <head><title>handler</title></head> <body> Hello from ME.<br /> </body> </html> END ModPerl::Util::exit(0); } ... ...

Replies are listed 'Best First'.
Re: Different context
by ikegami (Pope) on Apr 07, 2011 at 16:09 UTC
    Full blown browsers tend to replace 404 responses with their own, especially if the responses are small. Are you sure that the problem in on the server side?

        Definitely server side, but hey, got some more information to help you debug:

        $ GET -S http://tis.spaghetticoder.org/test/e34/M5_%28S38%29_SAL/Brake +s/Brake_lines/ GET http://tis.spaghetticoder.org/test/e34/M5_%28S38%29_SAL/Brakes/Bra +ke_lines/ --> 200 OK <html> <head><title>handler</title></head> <body> Hello from ME.<br /> </body> </html> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>200 OK</title> </head><body> <h1>OK</h1> <p>The requested URL /s/friendlyNew.pl was not found on this server.</ +p> </body></html>

        Note that the server returned a 200 status with two responses merged into one.

Re: Different context
by Anonymous Monk on Apr 07, 2011 at 13:37 UTC
    Unfortunately it doesn't work for me.

    My code, verbatim, doesn't work for you?