First, let's look at the header function.
The header () function sends the original HTTP header to the client, header (string, replace, http_response_code)
Php header 404:
Php code
The code is as follows: |
Copy code |
Header ("HTTP/1.1 404 Not Found"); exit; |
If the above code is ineffective, try the following code:
Php code
The code is as follows: |
Copy code |
Header ("Status: 404 Not Found "); |
The above page is only in the 404 status. If we want to verify it, we need to perform the following operations:
The code is as follows: |
Copy code |
@ Header ("http/1.1 404 not found "); @ Header ("status: 404 not found "); Include ("404.html"); // jump to a page. This method is recommended. Exit (); |
In this way, there will be both an error message and a beautiful page.
The code is as follows: |
Copy code |
Function getref () { $ Url = @ $ _ SERVER ['http _ referer']; If (! Empty ($ url )) { If (! Strstr ($ url, '111cn. Net ')&&! Strstr ($ url, '111cn. Net ')) { @ Header ("http/1.1 404 not found "); @ Header ("status: 404 not found "); Include ("404.html"); // jump to a page. This method is recommended. Exit (); } } Else { @ Header ("http/1.1 404 not found "); @ Header ("status: 404 not found "); Include ("404.html"); // jump to a page. This method is recommended. Exit (); } }
|
Apache is much simpler, ErrorDocument 404/404 .html
Note: After writing the code, you must use the topic 404 error page tool for testing. Otherwise, it may be difficult to return the code 200. You must check that the code is in the 404 status.