简体   繁体   中英

Custom 404 page - does it need a 404 header?

In my project, I'm routing all requests to index.php. Then I check $_SERVER['REQUEST_URI'] against a whitelist and display the relevent content.

Now, if the $_SERVER['REQUEST_URI'] does not match anything in my whitelist, I display some "page not found" text. In effect, it is a custom 404 error page.

My question is: do I need to write header('HTTP/1.0 404 Not Found'); before I output my HTML? What does it actually do? My error page is displayed regardless so is it important in this scenario?

Yes. That header is used by search engines, and others, to know the status of a page and act accordingly. (eg remove that page from their index, etc)

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