During PHP website development, an HTTP 404,403 error occurs when a user fails to access a website or fails to find a page. To improve user experience, we need to customize the 404 and 403 error pages, prompt the user to perform the next step or automatically jump to the appropriate access page.
The custom error page 404 and 403 methods are mainly configured through apache or htaccess. The htaccess configuration error page method is suitable for VM users. The following describes the configuration tutorial of error pages 404 and 403 in detail.
The methods for setting 404 and 403 error pages for apache and htaccess are basically the same. If you use htaccess for configuration, enable the htaccess configuration function. For details, refer to the recommended PHP Tutorial: tutorial on Setting Password protection for directory access using apache and htaccess.
Error Page 404, 403 configuration method
1. Open the apache httpd. conf configuration file or create a. htaccess configuration file.
2. Add the following information:
ErrorDocument 403/errpage/403.html
ErrorDocument 404/lerrpage/404.html
3. Save the apache httpd. conf or htaccess configuration file and restart apache.
4、create 403.html and 404.html files under the lerrpagefolder of the website root directory
Other Instructions
You can also automatically jump to the home page or another website when Error 404 or 403 is displayed on the website access page. The method is as follows:
ErrorDocument 403/index. php
ErrorDocument 404 http://www.minimalart.cn
The configuration information above is set to automatically jump to the homepage of the website when an HTTP 403 error occurs, and automatically jump to PHP tutorial network when an HTTP 404 error occurs.
Of course, for the sake of user experience, it is not recommended to automatically jump to the home page or other website settings.
Now the configuration of error pages 404 and 403 is completed through apache or htaccess.