Home » Categories » Multiple Categories

How to Change the Apache Error Messages

You can change the Apache error messages for a single app by adding ErrorDocument directives to the app's .htaccess file. For example, any of these formats work:

ErrorDocument 403 "Sorry, access to this page is forbidden."
ErrorDocument 500 http://example.com/server_error.html
ErrorDocument 503 /errors/service_unavailable.html
The format that uses an http or https URL will redirect the browser to the specified page.

To change the error pages globally, log in as root and create the following file:

/etc/apache-sp/conf.d/errors.conf
In that file, include this content:

ErrorDocument 403 "Sorry, access to this page is forbidden."
ErrorDocument 500 http://example.com/server_error.html
ErrorDocument 503 "Service Unavailable"
Then, restart Apache by running the following command as root:

sudo service apache-sp restart
Note that you should not use the path to a file when configuring this globally.

Changing 404 Error Messages
You can change the messages Apache sends for 404 errors by entering the following line in your app's .htaccess file:

ErrorDocument 404 /404.php
This format assumes you have a file called 404.php in your app's public directory.

However, this ErrorDocument directive will not catch 404 errors for requests that end in .php themselves. For example, a request for /this-does-not-exist.php will not be handled by the ErrorDocument directive because the request ends in .php.

To handle 404 errors for requests that end in .php, you should use rewrite rules that direct those requests to a specific PHP script, which will then send a 404 response.

To show a custom 404 page (using a file named 404.php, for example) when a requested script doesn't exist, add the following to your app's .htaccess file:

RewriteRule ^404\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.php [L]
Then, in that 404.php script, you would have something like this:

<?php
header("HTTP/1.0 404 Not Found");
// generate the HTML of the response here
?>

 

Ref:
https://serverpilot.io/docs/how-to-change-the-apache-error-messages/

 

Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
PHP and mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
Viewed 1683 times since Mon, Sep 28, 2020
PageSpeed: Enable Keep-Alive
Viewed 254 times since Tue, Mar 1, 2022
"End of script output before headers" in Apache + PHP
Viewed 479 times since Sun, Feb 27, 2022
Hide X-Powered-By: PHP
Viewed 459 times since Tue, Sep 15, 2020
Apache - Internal Server Error - LimitInternalRecursion
Viewed 363 times since Thu, Mar 10, 2022
PHP Warning: PHP Startup: Unable to load dynamic library ’curl’
Viewed 616 times since Thu, Feb 3, 2022
Server error: Connection reset by peer | End of script output before headers
Viewed 1354 times since Mon, Feb 28, 2022