• 技术文章 >后端开发 >PHP问题

    php怎么设置404页面

    藏色散人藏色散人2020-07-29 10:41:07原创1298

    php设置404页面的方法:首先找到并打开“apache\conf\extra\httpd-multilang-errordoc.conf”文件;然后修改404对应文件即可。

    推荐:《PHP教程

    php创建自定义404页面

    Apache服务器:

    修改 :apache\conf\extra\httpd-multilang-errordoc.conf 文件

    如下所示,修改404 对应文件即可

    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

    404文件在如下路径下:

    apache\error\404.html

    其他错误文件修改方式同上。

    修改完成后,重启Apache服务器即可!!!

    nginx服务器:

    1、创建自己的404.html页面放在网站根目录下。

    即:网站代码根目录/error/404.html

    (测试时,不知道为什么必须创建error文件夹,直接把404页面放到根目录下失败)

    2、修改nginx.conf文件在http定义区域加入:

    fastcgi_intercept_errors on;

    3、更改nginx.conf或虚拟主机的域名.conf在server区域加入(bitnami.conf):

    error_page  404  =  /404.html;

    4、重启nginx

    5、此时访问不存在url即跳转到自定义404页面

    以上就是php怎么设置404页面的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:php
    上一篇:php如何实现数字转汉字 下一篇:php怎么设置不提示错误
    线上培训班

    相关文章推荐

    • php跳转时404错误• php404错误页面怎么解决• 访问php报404错误的原因• php 404错误怎么改写

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网