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="width: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

猜你喜欢

转载自www.cnblogs.com/luojie-/p/11737080.html