zoukankan      html  css  js  c++  java
  • appache开启自定义404错误并编写404.html

    1,让apache支持.htaccess

    我们要找到apache安装目录下的httpd.conf文件,在里面找到

    <Directory />
    Options FollowSymLinks
    AllowOverride none
    </Directory>

    我们只要把none改all就重启apache就好了

    2、找到httpd.conf文件并修改
    phpStudy>Apache>conf下面的httpd.conf文件
    #ErrorDocument 404 /404.html
    将代码前面的#去掉,这部主要是关闭默认的404提示页面。

    3.在根目录下新建.htaccess文件,文件名就是  .htaccess

    ErrorDocument 404 /404.html
    第一个404是网页错误代码类型,后面的404.html是要响应的文件。就是说出现404类型错误,就显示对应的404.html文件。
    当然,这里文件名可以随便改,只要我们准备好同样的文件名的文件即可。

    .htaccess文件新建方法:
    新建一个文本文档,输入内容:
    ErrorDocument 404 /404.html
    然后另存为... 
    在另存为对话框中,输入文件名:
    ".htaccess"
    英文双引号引住文件名,然后保存即可。

    404.html内容我们可以自定义:

    <!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>catch the cat</title>
    <style type="text/css">
    p{ text-indent:2em; font-family:"微软雅黑"; font-size:16px; color: #63C; line-height:20px; text-align:left;}
    .noexist{width:100%; height:80px; padding-left:80px;border:30px auto; margin:0 auto;}
    .zxbanner{margin:0 auto;  text-align:center; width:100%; height: 420px;  overflow:hidden; position:relative; }
    .zxbanner .bnswf{width:1680px; height:420px; position: absolute; left: 50%; margin-left:-840px;}
    </style>
    </head>
     
    <body> 
    <div class="noexist">
    <div style="680px; margin:0 auto;">
    <p>你要查看的文件或者目录不存在。</p>
    <p>点击鼠标下点,把猫围住。猫的移动路线是贪心算法。</p></div>
    </div>
    </div>
    <div class="zxbanner"> 
     <embed class="bnswf" src="catch the cat.swf"></embed>
    </div>
    </body>
    </html>

    当访问了不存在的目录或者文件时候,就会如下效果:

    转载自:https://www.52pojie.cn/thread-1043107-1-1.html

    人生得意须尽欢,莫使金樽空对月.
  • 相关阅读:
    传输中文的乱码的原因及解决方式(两次encodeURI())转码;
    git密码配置
    后台界面设计之表单设计规范参考
    RDIFramework.NET开发框架在线表单设计整合工作流程的使用
    Electron,可以将web网页程序包装成桌面应用
    分布式/微服务必配APM系统,SkyWalking让你不迷路
    终端篇——Terminal三剑客之zsh
    高性能IO之Reactor模式
    uTools 你的办公利器
    JAVA 工具类库推荐 HuTool
  • 原文地址:https://www.cnblogs.com/luojie-/p/11737080.html
Copyright © 2011-2022 走看看