WordPress Hacks · Published January 2020
htaccess Custom Error Document Usage, Fix 404, 500 and Others
Apache only allows the ErrorDocument directive using the document root directory. If you don’t want to hard code full path of your error document in the htaccess file, but still need to use your own directory, you can use the following rewrite hack to redirect all errors to your static HTML file.
# Use Custom Error File in Current Folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* 404.html [L]
</IfModule>
Originally, if you were to type the full path of the document, you could use the following statements in your htaccess file:
ErrorDocument 500 /full-path-to/files/404.shtml
ErrorDocument 401 /full-path-to/files/404.shtml
ErrorDocument 402 /full-path-to/files/404.shtml
ErrorDocument 403 /full-path-to/files/404.shtml
ErrorDocument 404 /full-path-to/files/404.shtml