Xetolone
Xetolone

Reputation: 369

Is it relevant to make personalized 5** error pages?

I was following a tutorial to make personalized error pages with some lines like this in my apache conf:

ErrorDocument 400 /errors/errors.php
ErrorDocument 401 /errors/errors.php
ErrorDocument 402 /errors/errors.php
ErrorDocument 403 /errors/errors.php
ErrorDocument 404 /errors/errors.php
ErrorDocument 405 /errors/errors.php
ErrorDocument 500 /errors/errors.php
ErrorDocument 501 /errors/errors.php
ErrorDocument 502 /errors/errors.php
ErrorDocument 503 /errors/errors.php
ErrorDocument 504 /errors/errors.php
ErrorDocument 505 /errors/errors.php

and with some processing in the error.php based on $_SERVER["REDIRECT_STATUS"].

So far so good.

But I wondered if the server encounters an internal error, will it be able to execute the error.php file? Would it be smarter to provide error.html files in this case?

And I have a final question: how can I test those directives? How do I simulate errors other than 404?

Upvotes: 0

Views: 41

Answers (2)

Sammitch
Sammitch

Reputation: 32242

Yes, you have a valid concern that if the server is already generating 500-level errors that the server may not be capable of running the PHP script. The way that it has been solved where I work is:

  1. Create your error.php page.
  2. Create a cron job that periodically captures error.php to a static error.html page.
  3. Set error.html as your 500-level error page in Apache.

The reason we have this as a cron job is so that is changes are made to the general layout or surrounding content by our application those changes are captured without human intervention.

Upvotes: 1

Samuel Rondeau-Millaire
Samuel Rondeau-Millaire

Reputation: 1130

Yes 5** pages will be generated with a custom PHP page. To simulate a 5** and 4** error just use the headers like this :

<?php header('HTTP/1.1 500 Internal Server Error'); ?>

More informations about headers here.

There are some nice examples there.

Note : Overriding error pages will make you loose the error messages unless you handle them manually.

Upvotes: 0

Related Questions