Maison  >  Article  >  développement back-end  >  Comment configurer une page 404 en php

Comment configurer une page 404 en php

藏色散人
藏色散人original
2020-07-29 10:41:074730parcourir

Comment paramétrer la page 404 en PHP : recherchez et ouvrez d'abord le fichier "apacheconfextrahttpd-multilang-errordoc.conf" puis modifiez le fichier 404 correspondant.

Comment configurer une page 404 en php

Recommandé : "Tutoriel PHP"

php crée une page 404 personnalisée

Serveur Apache :

Modifier : le fichier apacheconfextrahttpd-multilang-errordoc.conf

est comme indiqué ci-dessous. Modifiez le fichier 404 correspondant

ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

Le fichier 404 est. comme suit Sous le chemin :

apacheerror404.html

La méthode de modification pour les autres fichiers d'erreur est la même que ci-dessus.

Une fois la modification terminée, redémarrez le serveur Apache ! ! !

Serveur nginx :

1. Créez votre propre page 404.html et placez-la dans le répertoire racine du site Web.

C'est-à-dire : répertoire racine du code du site Web/error/404.html

(Lors des tests, je ne sais pas pourquoi le dossier d'erreur doit être créé, mais en plaçant directement la page 404 dans le échec du répertoire racine)

2. Modifiez le fichier nginx.conf et ajoutez-le dans la zone de définition http :

fastcgi_intercept_errors on;

3. nom de domaine de l'hôte virtuel.conf et ajoutez-le dans la zone serveur ( bitnami.conf) :

error_page  404  =  /404.html;

4. Redémarrez nginx

5. il passera à la page 404 personnalisée

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn