简体   繁体   中英

Send 404 header after page load

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?

Call this first on error.php, before outputting any error text.

<?php
    header("HTTP/1.0 404 Not Found");
?>

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.

PHP docs header function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM