Reputation: 1383
I'm trying to send a 404 header after the page loads and was wondering if there were any solutions. Essentially, a database is searched to see if the url is valid and corresponds to valid content. If it doesn't, it will "include()" an error.php file.
Is there anyway that I can write an htaccess rule that says, whenever this file is loaded, throw a 404? How else could I send that 404 inside of the error.php file, since it is not the first thing to be displayed?
Upvotes: 0
Views: 1053
Reputation: 4819
Call this first on error.php, before outputting any error text.
<?php
header("HTTP/1.0 404 Not Found");
?>
Upvotes: 3
Reputation: 10666
You can always use the header-function, just remember to do that before you output anything else.
I would recomend doing that instead of including another file, and then configure your server to serve an appropiate 404 file.
Upvotes: 1