[cgiapp] Re: Best practices for returning 404/file-not-found pages
inside and outside of mod_perl
Mark Stosberg
mark at summersault.com
Wed May 7 09:53:56 EDT 2008
> > 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('/');
> }
Good to know! Had you run into the "500/eof/chunk" error as well, before you
added the redirect?
The approach I settled on was to patch LWP to quit throwing that error, as
"real" browsers seem to deal with it OK.
The other behavior I reported about "can't find modules" I think was a separate configuration issue in my case.
Thanks for the redirect tip, Rhesa!
Mark
--
. . . . . . . . . . . . . . . . . . . . . . . . . . .
Mark Stosberg Principal Developer
mark at summersault.com Summersault, LLC
765-939-9301 ext 202 database driven websites
. . . . . http://www.summersault.com/ . . . . . . . .
More information about the cgiapp
mailing list