In PHP website development, when users make an error when accessing the website and cannot find the page, HTTP 404 and 403 error messages will appear. In order to improve the user experience, we need to customize 404 and 403 error pages to prompt the user for the next step or automatically Jump to the appropriate access page.
The method of customizing error pages 404 and 403 is mainly configured through apache or htaccess. The htaccess method of configuring error pages is suitable for virtual host users. The following details the configuration tutorial for error pages 404 and 403.
The methods for setting 404 and 403 error pages in apache and htaccess are basically the same. If you use htaccess for configuration, be sure to enable the htaccess configuration function. For details, please refer to the PHP recommended tutorial: Using apache and htaccess to set password protection for directory access configuration tutorial.
Error page 404, 403 configuration method
1. Open the apache httpd.conf configuration file or create a new .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 new 403.html and 404.html files in the lerrpage folder of the website root directory
Other instructions
You can also automatically jump to the homepage or another website when a 404 or 403 error message appears on the website access page. The method is as follows
ErrorDocument 403 /index.php
ErrorDocument 404 http://www.minimalart.cn
The above configuration information is set to automatically jump to the homepage of the website when an HTTP 403 error occurs, and to automatically jump to the PHP tutorial website when an HTTP 404 error occurs.
Of course, due to user experience considerations, it is not recommended to automatically jump to the homepage or other websites.
Now the configuration of error pages 404 and 403 through apache or htaccess is completed.