1.修改config.php
// 文件路径:application/config.php
// 自定义错误码模板
'http_exception_template' => [
// 定义404错误的模板渲染
404 => APP_PATH . 'common/view/404/404.html',
],
2.需要把debug关闭才能生效
在.env文件中把debug = true,改为debug = false
3.贴一个404页面源码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404-对不起!您访问的页面不存在</title>
<style type="text/css">
.head404{ width:580px; height:234px; margin:50px auto 0 auto; background:url(__CDN__/assets/img/head404.png) no-repeat; }
.txtbg404{ width:499px; height:169px; margin:10px auto 0 auto; background:url(__CDN__/assets/img/txtbg404.png) no-repeat;}
.txtbg404 .txtbox{ width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;}
.txtbg404 .txtbox p {margin:5px 0; line-height:18px;}
.txtbg404 .txtbox .paddingbox { padding-top:15px;}
.txtbg404 .txtbox p a { color:#eee; text-decoration:none;}
.txtbg404 .txtbox p a:hover { color:#FC9D1D; text-decoration:underline;}
</style>
</head>
<body bgcolor="#494949">
<div class="head404"></div>
<div class="txtbg404">
<div class="txtbox">
<p>我们深感抱歉,有一些错误发生了...</p>
</div>
</div>
</body>
</html>
图像资源
4.页面效果
5.开源404页面推荐
缤纷多彩的404页面(404.html) - 勿埋我心