html - Display 404 document from htaccess after sending 404 header in PHP -
in php use following code indicate page not found:
header("http/1.0 404 not found");exit();
in .htaccess
file have following line handle 404 custom document:
errordocument 404 /404.html
now when send php 404 header expect show custom 404.html
defined in .htaccess
instead shows message "this link appears broken". doesn't show custom 404 page , if remove line .htaccess
still won't display regular 404 page of server , shows broken link message.
so how make show 404 page when send header in php?
the problem here custom error document denoted errordocument
isn't processed unless url processing pipeline can't find file (or handler) url points to. in case, processing pipeline does find file, php file, never reaches 404 on own errordocument
never applied.
when apache uses php handler run php file, , php file decides return 404, not need provide 404 response code, html error document well. don't see default apache error document because apache never thinks request 404 (it handed request off php file). need this:
header("http/1.0 404 not found"); include('404.html'); exit();
Comments
Post a Comment