Home > Backend Development > PHP Tutorial > About ThinkPHP's method of accessing non-existent modules and jumping to the 404 page

About ThinkPHP's method of accessing non-existent modules and jumping to the 404 page

不言
Release: 2023-04-01 14:34:01
Original
3733 people have browsed it

This article mainly introduces the method of ThinkPHP to jump to the 404 page when accessing non-existent modules. Friends who need it can refer to it

First create a new file EmptyAction.class.php in ACTION and its code As follows:

<?php 
 class EmptyAction extends Action{ 
 function _empty(){ 
  header("HTTP/1.0 404 Not Found");//使HTTP返回404状态码 
  $this->display("Public:404"); 
 } 
 } 
 ?>
Copy after login

When using the apache server, you need to add ErrorDocument 404 /404.html to the website configuration in apache.

When using the iis server, you need to set the 404 error page under IIS/ASP.net in iis.

Open the apache httpd.conf configuration file or create a new .htaccess configuration file

First, modify the settings of the application root directory, open the "web.config" file for editing, and add the following content:

<configuration>
 <system.web>
 <customErrors mode=”On” defaultRedirect=”error.asp”>
 <error statusCode=”404″ redirect=”notfound.asp” />
 </customErrors>
 </system.web>
 </configuration>
Copy after login

Note: In the above example, "error.asp" is the system's default 404 page, and "notfound.asp" is a customized 404 page. Please modify the corresponding file name when using it.
Then, add to the customized 404 page "notfound.asp":

<%
 Response.Status = “404 Not Found”
 %>
Copy after login

php's 404 page:

 if(//如果没有任何结果)
   {
   //以前是仅仅显示“该帖子已经不存在”的提示,现在是:
   require(&#39;/404.php&#39;);
   @header(&#39;HTTP/1.1 404 Not Found&#39;&#39;);
   @header(&#39;Status: 404 Not Found&#39;);
   exit;
   }
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's learning Helpful, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

How to solve errors about PHP WARNING: SESSION_START() [FUNCTION.SESSION-START]

About the method of setting http status pages such as 404 and 403 in thinkPHP5 framework

The above is the detailed content of About ThinkPHP's method of accessing non-existent modules and jumping to the 404 page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template