Apache, cPanel and ErrorDocument
If you're using a cPanel-powered Apache server, there's a chance it may not be setup in the best way.
The same issue might manifest itself in two ways: confusing error messages and ignored htaccess directives.
By default, cPanel is setup to know about five different error codes:
- 400 Bad Request
- 401 Authorization Required
- 403 Forbidden
- 404 Not Found
- 500 Internal Server Error
When each of these occurs, it will look in the webroot for a .shtml file relating to that error.
If that file doesn't exist, in addition to the standard error text, you will also get the message:
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Which looks a bit crappy as well as having the effect of doubling up your logs with redundant entries, making it harder to see the valid log entries.
However, a more significant issue can occur when an error is triggered that is not one of the five above - specifically, if you are attempting to deliberately send a 410 Gone response to indicate that a document no longer exists.
If Apache hasn't been instructed to send an appropriate document, the directive
triggering that response is effectively ignored - this can occur for both
mod_alias's Redirect (or RedirectMatch) and also if you
specify the [G]
flag on a mod_rewrite RewriteRule.
Unlike the previous problem, there might be no log entries to indicate the problem, and your rule is silently ignored - causing incorrect behaviour for any pages it was supposed to handle.
The solution to both these problems is to specify an ErrorDocument line
for each status code, and tell Apache to use the default
document - that is,
not to bother looking for a particular file and just send the standard message.
ErrorDocument 400 default
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 410 default
ErrorDocument 500 default
Add the above to your global Apache config (or in appropriate .htaccess files) to override the code.shtml documents that cPanel has set and you will get the standard Apache messages, you wont get doubled up log entries, and you will ensure that your redirects work as expected.
Of course, if you don't want the default Apache message, you can specify your own text, filename, or URL to use instead. Perhaps you have error pages already setup, in which case you might want something like:
ErrorDocument 403 /index.cfm?action=errors.forbidden
ErrorDocument 404 /index.cfm?action=errors.notfound
ErrorDocument 410 /index.cfm?action=errors.gone
For more details on what you can use, see the ErrorDocument documentation.
Oh, and one last note - all the Apache documentation links on this page are to
the docs for the latest current version - if you are using an older version,
substitute current
in the URL for, e.g. 2.2
, to get the docs for that
version, just in case there are any differences.