How to set thinkphp to add 404 page thinkphp to set 404 page

Source: Internet
Author: User
It is not necessary to try to add it to the server first. thinkphp itself provides the 404 page processing mechanism. we only need to define an EmptyAction under lib. class. php and implement the following methods:

It is not necessary to try to add it to the server first. thinkphp itself provides the 404 page processing mechanism. we only need to define an EmptyAction under lib. class. php and implement the following methods:

  1.  
  2. Class EmptyAction extends Action {
  3.  
  4. Function _ empty (){
  5.  
  6. Header ("HTTP/1.0 404 Not Found ");
  7.  
  8. $ This-> display ('public: 404 ');
  9.  
  10. }
  11.  
  12. // 404
  13.  
  14. Function index (){
  15.  
  16. Header ("HTTP/1.0 404 Not Found ");
  17.  
  18. $ This-> display ('public: 404 ');
  19.  
  20. }
  21.  
  22. }
  23.  
  24. ?>

The preceding code directly defines the empty module and the empty operation to achieve 404 redirection. However, it is important to set the header. Otherwise, the returned status will be 200. this class corresponds to a page template named 404 in the Public Template directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.