Home  »  GuidesLibrariesProgrammingTechnology   »   ErrorDocument 404 vs FallbackResource in Apache .htaccess on Ubuntu

ErrorDocument 404 vs FallbackResource in Apache .htaccess on Ubuntu

As we discuss the debate of ErrorDocument 404 vs FallbackResource in Apache, it is good to note that Apache provides the ErrorDocument directive to help you catch all types of error responses. When caught the server can redirect to a more friendly URL.

The directive works by specifying the HTTP status code to catch and the URL to rewrite to. If you want to catch all 500 error responses, add the following line to your .htaccess file. The instructions here work on Mac, Windows, and Linux systems such as Ubuntu, CentOS, Debian, RHEL, and others.

ErrorDocument 500 /error-500.html

ErrorDocument in Apache Server or VirtualHost Config

The ErrorDocument directive associates each type of error can be set within the virtual host that is currently defined. The only difference here is that you have to reload or restart the Apache server to apply changes

$ sudo systemctl reload apache2

or

$ sudo service apache2 reload

So, What About FallbackResource Directive?

In Apache, you can use the FallbackResource directive to set a handler for any URL that doesn’t map to anything in your filesystem, and would otherwise return HTTP 404 (Not Found). This will cause requests for non-existent files to be handled by the file specified in the directive.
Here’s an example:

FallbackResource /notfound-404.php

ErrorDocument 404 vs FallbackResource

Both of these directives behave similarly only that in the case of FallbackResource you do not specify the HTTP status code. The other difference is FallbackResource will not log an entry in the error logs that way you do not have to be concerned about your error logs growing too unnecessarily large.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.