Home  >  Article  >  Backend Development  >  How to set up 404 page in php

How to set up 404 page in php

藏色散人
藏色散人Original
2020-07-29 10:41:074728browse

How to set the 404 page in php: first find and open the "apache\conf\extra\httpd-multilang-errordoc.conf" file; then modify the 404 corresponding file.

How to set up 404 page in php

Recommended: "PHP Tutorial"

php creates a custom 404 page

Apache server:

Modify: apache\conf\extra\httpd-multilang-errordoc.conf file

As shown below, modify the 404 corresponding file

ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

404 file is in the following path:

apache\error\404.html

The modification method for other error files is the same as above.

After the modification is completed, restart the Apache server! ! !

nginx server:

1. Create your own 404.html page and place it in the root directory of the website.

That is: website code root directory/error/404.html

(During the test, I don’t know why the error folder must be created, and it failed to directly put the 404 page in the root directory)

2. Modify the nginx.conf file and add in the http definition area:

fastcgi_intercept_errors on;

3. Change nginx.conf or the domain name of the virtual host.conf and add it in the server area ( bitnami.conf):

error_page  404  =  /404.html;

4. Restart nginx

5. At this time, if the url does not exist, it will jump to the custom 404 page

The above is the detailed content of How to set up 404 page in php. For more information, please follow other related articles on the PHP Chinese website!

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