Mark Stosberg wrote:
In the past, the way I returned 404 page through CGI::App was something like this:

  return $self->error(title => 'Page not found');

I learned that is too late to return a real 404 error running under CGI, so the page comes back with a 200 status code, which isn't quite right.

More recently, I learned that with mod_perl, I learned that I can get the system to return a true 404, so I updated the logic to do that when possible:

  if (exists $ENV{MOD_PERL}) {
    $self->header_add( -status => 404 );
    return '';
  }
  else {
     return $self->error(title => 'Page not found')
  }


I recently ran into this myself, and discovered that setting the header_type to 'redirect' fixed the issue:

   if (exists $ENV{MOD_PERL}) {
     $self->header_add( -status => 404 );
     return $self->redirect('/');
   }

Note I'm using the CAP::Redirect plugin, but the general principle holds. It doesn't matter where you redirect to either, as it always trigggers the ErrorDocument. Just don't return any content of your own.

At least, this works for me under Apache 2.2.2 / mod_perl 2.0.3

HTH,
Rhesa

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################

Reply via email to