Script qui génère des pages d'erreur HTTP en HTML statique

Certains ne sont pas reconnus par le serveur web donc commentés sinon Apache produit une erreur visible dans le log d'erreurs.

Pour chaque élément du tableau, remplace 3 variables dans un template HTML par les valeurs du tableau, écrit le fichier .html et affiche le code pour le .htaccess.
<?php
$err = array(
    array(400,'Bad Request',                'The server did not understand the request'),
    array(401,'Unauthorized',                'The requested page needs a username and a password'),
    array(402,'Payment Required',            'You can not use this code yet'),
    array(403,'Forbidden',                    'Access is forbidden to the requested page'),
    array(404,'Not Found',                    'The server can not find the requested page'),
    array(405,'Method Not Allowed',            'The method specified in the request is not allowed'),
    array(406,'Not Acceptable',                'The server can only generate a response that is not accepted by the client'),
    array(407,'Proxy Authentication Required','You must authenticate with a proxy server before this request can be served'),
    array(408,'Request Timeout',            'The request took longer than the server was prepared to wait'),
    array(409,'Conflict',                    'The request could not be completed because of a conflict'),
    array(410,'Gone',                        'The requested page is no longer available '),
    array(411,'Length Required',            'The "Content-Length" is not defined. The server will not accept the request without it '),
    array(412,'Precondition Failed',        'The precondition given in the request evaluated to false by the server'),
    array(413,'Request Entity Too Large',    'The server will not accept the request, because the request entity is too large'),
    array(414,'Request-url Too Long',        'The server will not accept the request, because the url is too long. Occurs when you convert a "post" request to a "get" request with a long query information'),
    array(415,'Unsupported Media Type',        'The server will not accept the request, because the media type is not supported '),
    array(416,'Requested range unsatisfiable','Champs d’en-tête de requête « range » incorrect.'),
    array(417,'Expectation Failed',            'Comportement attendu et défini dans l’en-tête de la requête insatisfaisante.'),
/*
    //array(418,'I’m a teapot',                    '« Je suis une théière ». Ce code est défini dans la RFC 23249 datée du premier avril 1998, Hyper Text Coffee Pot Control Protocol.'),
    array(421,'Bad mapping / Misdirected Request','La requête a été envoyée à un serveur qui n\'est pas capable de produire une réponse (par exemple, car une connexion a été réutilisée).'),
    array(422,'Unprocessable entity',            'WebDAV : L’entité fournie avec la requête est incompréhensible ou incomplète.'),
    array(423,'Locked',                        'WebDAV: L’opération ne peut avoir lieu car la ressource est verrouillée.'),
    array(424,'Method failure',                'WebDAV: Une méthode de la transaction a échoué.'),
    //array(425,'Unordered Collection',            'WebDAV: RFC 364810. Ce code est défini dans le brouillon WebDAV Advanced Collections Protocol, mais est absent de Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol.'),
    array(426,'Upgrade Required',                'RFC 281711 Le client devrait changer de protocole, par exemple au profit de TLS/1.0.'),
    array(428,'Precondition Required',            'RFC 658512 La requête doit être conditionnelle.'),
    array(429,'Too Many Requests',                'RFC 658513 Le client a émis trop de requêtes dans un délai donné.'),
    array(431,'Request Header Fields Too Large','RFC 658513 Les entêtes HTTP émises dépassent la taille maximale admise par le serveur.'),
    //array(449,'Retry With',                    'Code défini par Microsoft. La requête devrait être renvoyée après avoir effectué une action.'),
    //array(450,'Blocked by Windows Parental Controls','Code défini par Microsoft. Cette erreur est produite lorsque les outils de contrôle parental de Windows sont activés et bloquent l’accès à la page.'),
    array(451,'Unavailable For Legal Reasons',    'Ce code d\'erreur indique que la ressource demandée est inaccessible pour des raisons d\'ordre légal.'),
    //array(456,'Unrecoverable Error',            'WebDAV : Erreur irrécupérable.'),
*/
    array(500,'Internal Server Error',            'The request was not completed. The server met an unexpected condition'),
    array(501,'Not Implemented',                'The request was not completed. The server did not support the functionality required'),
    array(502,'Bad Gateway',                    'The request was not completed. The server received an invalid response from the upstream server'),
    array(503,'Service Unavailable',            'The request was not completed. The server is temporarily overloading or down'),
    array(504,'Gateway Timeout',                'The gateway has timed out'),
    array(505,'HTTP Version Not Supported',        'The server does not support the "http protocol" version')
/*
    array(506,'Variant Also Negotiates',        'RFC 229517 : Erreur de négociation. Transparent content negociation.'),
    array(507,'Insufficient storage',            'WebDAV : Espace insuffisant pour modifier les propriétés ou construire la collection.'),
    array(508,'Loop detected',                    'WebDAV : Boucle dans une mise en relation de ressources (RFC 584218).'),
    //array(509,'Bandwidth Limit Exceeded',        'Utilisé par de nombreux serveurs pour indiquer un dépassement de quota.'),
    array(510,'Not extended',                    'RFC 277419 : la requête ne respecte pas la politique d\'accès aux ressources HTTP étendues.'),
    array(511,'Network authentication required','RFC 658513 : Le client doit s\'authentifier pour accéder au réseau. Utilisé par les portails captifs pour rediriger les clients vers la page d\'authentification.')
*/
);


$template = '<!doctype html>
<html>
<title>[NUM] [TITRE]</title>
<style>
body {
    background-color: #212121;
    background-image:url(/err/bg.png);
    margin-top:50px;
    text-align:center;
    color:silver;
}
h1,h2 {
    font-size:4em;
    color: #FF0000;
    text-shadow: 0 -1px 4px #FFF, 0 -2px 10px #ff0, 0 0 20px #ff8000, 0 -18px 40px #F00;
}
h2 { font-size:2em;}
</style>
<body>
<h1>ERREUR [NUM]</h1>
<h2>[TITRE]</h2>
<h3>[TEXTE]</h3>
</body>
</html>';

$mots = array("[NUM]", "[TITRE]", "[TEXTE]");

for($n=0; $n<count($err); $n++)
{
    $repl = array($err[$n][0], $err[$n][1], $err[$n][2]);
    $str = str_replace($mots, $repl, $template);

    file_put_contents($err[$n][0].'.html', $str);

    echo "ErrorDocument ".$err[$n][0]." /err/".$err[$n][0].".html<br/>\n";
}
?>
Tous ces fichiers sont placés dans un dossier err à la racine du site.
Ainsi le .htacces ressemble à :
# PAGE D'ERREUR PERSO
ErrorDocument 400 /err/400.html
ErrorDocument 401 /err/401.html
ErrorDocument 402 /err/402.html
ErrorDocument 403 /err/403.html
ErrorDocument 404 /err/404.html
ErrorDocument 405 /err/405.html
ErrorDocument 406 /err/406.html
ErrorDocument 407 /err/407.html
ErrorDocument 408 /err/408.html
ErrorDocument 409 /err/409.html
ErrorDocument 410 /err/410.html
ErrorDocument 411 /err/411.html
ErrorDocument 412 /err/412.html
ErrorDocument 413 /err/413.html
ErrorDocument 414 /err/414.html
ErrorDocument 415 /err/415.html
ErrorDocument 416 /err/416.html
ErrorDocument 417 /err/417.html
ErrorDocument 500 /err/500.html
ErrorDocument 501 /err/501.html
ErrorDocument 502 /err/502.html
ErrorDocument 503 /err/503.html
ErrorDocument 504 /err/504.html
ErrorDocument 505 /err/505.html
Tester une page 404

La plupart du temps on voudra modifier le template HTML et relancer le script, récupérer et coller le code pour le fichier .htaccess.