Home  >  Article  >  Backend Development  >  PHP defines the implementation code of the 404 page

PHP defines the implementation code of the 404 page

高洛峰
高洛峰Original
2016-12-01 11:07:331538browse

Core code:
Copy code The code is as follows:
@header("http/1.1 404 not found");
@header("status: 404 not found");
echo 'echo 404';
exit();

If you need to load a 404 page, you can use the following code, mainly pay attention to the file path
Copy the code The code is as follows:
@header("http/1.1 404 not found");
@header("status: 404 not found");
include ("../../404.htm");
exit();

To check whether the 404 setting is successful, you can use the firebug plug-in of firefox to check

Viewing method

If firebug has been installed, use firefox Open the page where you want to check the 404 status code in the browser, click the bug icon in the lower right corner, start the "Network" tab, and open "Network? All/html? headers" in order; if everything is normal, you can see headers, responses All page parameters included.

The impact of 404 pages on the website

The impact on SEO is not great. But something is better than nothing. If you have this permission, you'd better set up a 404 page. This thing is the same as the site map. Not all websites need to set it up, but sometimes it is necessary to set it up.
When considering whether to set up a 404 page, you should consider user experience more than SEO.

Let’s take a look at the apache 404 definition
The method to set the 404 error page in apache and set the 404 error page for the apache server is very simple, just add the following content to the .htaccess file:
errordocument 404 /notfound.php

Statement:
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