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

相關文章
相關標籤/搜索