Configuring error pages for specific HTTP status codes using `.htaccess` involves using the `ErrorDocument` directive. Here’s how you can set it up:
1. Create or edit the .htaccess file: If you don’t already have an `.htaccess` file in your website’s root directory, create one. If it exists, open it for editing.
2. Add the `ErrorDocument` directive: Use the following syntax to specify custom error pages for specific HTTP status codes:
ErrorDocument <HTTP_STATUS_CODE> /path/to/custom/error/page
Replace `<HTTP_STATUS_CODE>` with the actual HTTP status code and `/path/to/custom/error/page` with the path to your custom error page. Here’s an example:
ErrorDocument 404 /errors/404.html
This configuration will display the custom error page `404.html` located in the `/errors` directory when a 404 error (page not found) occurs.
3. Save the changes: Save the `.htaccess` file after adding the `ErrorDocument` directives.
4. Test: Test the custom error pages by intentionally triggering the corresponding HTTP status codes (e.g., by accessing a non-existent page to trigger a 404 error) and verify that the custom error pages are displayed as expected.
Remember to make sure that the paths specified in the `ErrorDocument` directive are correct relative to the web root directory.