搜索
热搜: 活动 交友 discuz
查看: 21742|回复: 129

[论坛] Discuz设置404页面教程-实用

[复制链接]

29

主题

30

帖子

164

积分

超级版主

Rank: 8Rank: 8

积分
164
发表于 2021-7-14 00:05:32 | 显示全部楼层 |阅读模式
本帖最后由 Jimoy 于 2021-7-14 00:17 编辑

1.首页新建一个文本文件命名为 404.php,然后用文本编辑器打开,填入以下代码,并保存;

  1. <?php
  2. define('CURSCRIPT', '404');
  3. require './source/class/class_core.php';
  4. C::app()->init();
  5. $navtitle = "404提示"; // 这里修改404页面标题
  6. include template('common/404'); // 这里是你的404页面模版
  7. ?>
复制代码
将$navtitle = "404提示"这行代码中的“404提示”修改为你的404页面的标题,保存之后将404.php上传到你网站的根目录

2.接下来用编辑器打开你的404的html文件(后缀为.html或者.htm),去掉head,body标签,只留下<body>与</body>中间的那段代码,其他全去掉
然后在最上面一行加上{template common/header},在最下面一行加上{template common/footer},保存

3.然后上传到你的服务器上的template\default\common目录里,如果你不是用的默认模板,记得将default改成你模板目录名,

4.最后,apache修改服务器配置文件上的404页面声明也就是把 ErrorDocument 404 /404.html改成ErrorDocument 404 /404.php,不同服务器修改教程大家自行去网上找,然后你就访问一个你网站没有的路径,比如在你的域名后随便打几个字母,如http://bbs.itqu.net/errorpage就可以看到效果

最后再用HTTP返回码查询工具检测一下HTTP状态,这里成功检测出状态码为404

---------------------------------------------   华丽分割线  ---------------------------------------------------
如果是nginx,在配置文件里可以看到
  1. #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
  2.     error_page 404 /404.html;
  3.     error_page 502 /502.html;
  4. #ERROR-PAGE-END
复制代码
就直接在根目录放一个404.html
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>很抱歉,网页不存在!</title>

  6. <style type="text/css">
  7. body {margin: 0px; padding:0px; font-family:"微软雅黑", Arial, "Trebuchet MS", Verdana, Georgia,Baskerville,Palatino,Times; font-size:16px;}
  8. div{margin-left:auto; margin-right:auto;}
  9. a {text-decoration: none; color: #1064A0;}
  10. a:hover {color: #0078D2;}
  11. img { border:none; }
  12. h1,h2,h3,h4 {
  13. /*  display:block;*/
  14.     margin:0;
  15.     font-weight:normal;
  16.     font-family: "微软雅黑", Arial, "Trebuchet MS", Helvetica, Verdana ;
  17. }
  18. h1{font-size:44px; color:#0188DE; padding:20px 0px 10px 0px;}
  19. h2{color:#0188DE; font-size:16px; padding:10px 0px 40px 0px;}

  20. #page{width:910px; padding:20px 20px 40px 20px; margin-top:80px;}
  21. .button{width:180px; height:28px; margin-left:0px; margin-top:10px; background:#009CFF; border-bottom:4px solid #0188DE; text-align:center;}
  22. .button a{width:180px; height:28px; display:block; font-size:14px; color:#fff; }
  23. .button a:hover{ background:#5BBFFF;}
  24. </style>
  25. </head>

  26. <body>
  27. <div id="page" style="border-style:dashed;border-color:#e4e4e4;line-height:30px;background:url(sorry.png) no-repeat right;">
  28.     <h1>网页不存在,即将跳转新网址</h1>
  29.     <h2>The website is moving. It is about to jump to the new website. </h2>
  30.     <meta http-equiv="refresh" content="1;url=http://bbs.itqu.net">
  31.     <font color="#666666">若网页未能自动跳转新网址,请点击下面按钮进行跳转!</font><br /><br />
  32.     <div class="button">
  33.         <a href="http://bbs.itqu.net" title="进入新网址">进入新网址</a>
  34.     </div>
  35. </div>
  36. </body>
  37. </html>
复制代码
上面代码可以在访问不到的时候自动跳转首页!







上一篇:WordPress个人博客搭建教程
下一篇:Discuz3.2 新用户插入数据库SQL
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

抖音账号
关注抖音
加入粉丝群,抽取论坛金币


Archiver|手机版|小黑屋|IT趣-GEEK社区

GMT+8, 2024-7-27 10:28 , Processed in 0.064082 second(s), 22 queries .

Powered by Discuz! X3.4. 技术支持 by 巅峰设计

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表