How do I set-up custom error pages using .htaccess?

There are two different ways to display error messages using Plesk on Linux. The first is through Plesk itself, using the Custom Error Documents option and five files in the error_docs/ directory under each domain's home. The second is by using a .htaccess file to change Apache's settings directly. This article covers the second option. For more details about the first option and how to use it, please see How do I setup custom error pages using Plesk?


If you are not comfortable working directly with the .htaccess configuration file, it is not recommended that you follow this guide. Please use the first option instead. A bad setting with a .htaccess file will cause a 500 error and leave your site unavailable until the error has been corrected or the .htaccess file deleted.


Also, this setting can be used in conjunction with the first option as well, as it will form a default for the domain while the .htaccess file can be used to override those settings for a whole domain or just a group of directories.


One big advantage of using .htaccess files to manage errors is that you can redirect them to a script, instead of just providing static pages. For example, our .htaccess file redirects errors to a PHP script which then sends our Support Team an e-mail, informing them of the problem. Using this we can find missing pages, bad links and general problems with our web site very quickly.


Setup


Setting this up is quite easy. However, you must first have the page(s) or script available otherwise you will get the error (e.g. 403 error) and a 404 error as well, as it couldn't find the page you told it to display.


For each error you want to redirect, add the following directive to a .htaccess file:


ErrorDocument 000 /path/to/file

where 000 is the error number (e.g. 400, 404 or 500) and /path/to/file is the location of the error document on the web site (not on the hard-drive). For example, if you have created an error page at http://example.com/error/404.html, then just use the path after the domain (example.com): /error/404.html, i.e.


ErrorDocument 404 /error/404.html

You can also point it to a script with options, e.g.


ErrorDocument 404 /error.php?err=404

Finally, you will need to do this for each error you want to report. Any errors not covered by this method will fall back either to the Custom Error Documents options (if set, and option avilable), or to the default reporting method in Apache itself. For example, the following file will cover most errors:


ErrorDocument 400 /error/bad-request.html
ErrorDocument 401 /error/unauthorised.html
ErrorDocument 403 /error/forbidden.html
ErrorDocument 404 /error/file-not-found.html
ErrorDocument 500 /error/internal-server-error.html
  • 129 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

How do I set-up custom error pages in Plesk?

There are two different ways to display error messages using Plesk on Linux. The first is...

How do I set-up custom error pages using .htaccess?

There are two different ways to display error messages using Plesk on Linux. The first is through...

What is Hotlinking and how do I prevent it?

If you notice a surge in the traffic coming to your site, it may not be because you are receiving...

What is an injection-based Spam attack?

Many of the older techniques for sending Spam out via remote servers either involves searching...

How do I create a cron job?

A cron job (run by the cron daemon, or cron service) is a request for the server to run a...