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