appache开启自定义404错误并编写404.html

1,让apache支持.htaccess

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

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

咱们只要把none改all就重启apache就行了css

 

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

 

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

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

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

 

404.html内容咱们能够自定义:ide

 

<!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>

 

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

 

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

相关文章
相关标签/搜索