Introduction
We've all seen the dreaded Error 404 message - the result of broken links and mistyped URLs. You've probably been on some websites where the error pages are customised with their own logo and message, and I'm sure you'll agree that it looks far more professional than the standard one.
In this article we'll show you how to use Apache's .htaccess file to make your own customised error 404 pages.
Create the .htaccess file
Create a new text file on your computer, and call it "htaccess.txt". Enter the following lines:
<Files .htaccess> order allow,deny deny from all </Files> ErrorDocument 404 http://www.youdomain.com/error404.htm
The first part stops people viewing your .htaccess file. The second part tells Apache to redirect any 404 errors to the file "error404.htm".
Create the 404 page
Now you need to create the 404 page. Make a new web page called "error404.htm" and enter "This is my 404 page". Enter it a few dozen times, as Internet Explorer won't display it unless the file is over 512 bytes.
Once it's done, login to your webspace with your FTP client, and create a new folder called "errordocs". Upload the file "error404.htm" to this directory. Upload "htaccess.txt" to the root of your webspace and rename it to ".htaccess" ó there's no .txt at the end, no name in front, just ".htaccess". If the file seems to vanish don't worry, some FTP clients don't display it ó the file's still there.
Trying it out
Now you need to see if it works. Type the URL of your website in your browser and add a random file name at the end. Something like "http://www.yoursite.com/dgsgdgsdgdsgg.htm".
If everything has worked properly, you should now be seeing your custom error message. If not, then it's possible your web host doesn't allow you to have your own .htaccess files. You may want to contact them and ask.
If it worked then you can now make a proper 404 page. You can have your own images, text, in fact anything else you can have in a normal web page. The best 404 pages have the site logo and a few simple lines explaining what's happened. If you have a site search, you could put that on it too in order to help visitors find what they're looking for.
Taking it further
There's several other error documents that you might wish to customise.
400 - Bad request
401 - Authorization Required
403 - Forbidden directory
404 - Page not found
500 - Internal Server Error
For each one you want to use, simply add a line to your .htaccess file and create the corresponding page.
<Files .htaccess> order allow,deny deny from all </Files> ErrorDocument 403 http://www.youdomain.com/error403.htm ErrorDocument 404 /error404.htm ErrorDocument 500 /error405.htm
from: http://www.totallyphp.co.uk/custom-error-pages-using-htaccess
相关推荐
.htaccess伪静态 适用方维分享系统以及其他php
.htaccess文件教程 301重定向 自定义404错误.zip
如何让IIS支持Apache .htaccess 伪静态规则 ? 很简单,一键安装覆盖即可,内含说明步骤与安装包。
如果文件不在网站的根目录下,你只需要把路径设置为: <br>ErrorDocument 500 /errorpages/500.html<br>These are some of the most common errors:<br>以下是一些最常用的错误: <br>401 - Authorization...
nginx支持.htaccess伪静态rewrite的方法.docx
ThinkPHP的去除URL中的index.php的.htaccess文件
.htaccess 一般很少有人接触到,对于非专业的织梦新手来说,这个非常重要,包括一些404页面设置,网站短域名跳转等都可以在这里面完成。
有外贸需求,需要防止爬虫,像中国和香港的IP,使禁止访问.htaccess,不是非常全,有一些作用,希望能给到大家帮助
可能很多朋友都常用nginx不支持.htaccess,只有apache才支持.htaccess文件,其实这是错误的看法nginx也是支持.hatccess的哦,下面我来给各位总结一下配置方法。 其实nginx和.htaccess一点关系都没有,只是一大堆人...
apache开启.htaccess及.htaccess的使用方法.docx
php 页面重定向 通过.htaccess 定制404错误页面
在Google上搜索的资料很多人都说nginx目前不支持.htaccess文件,我按照nginx的规则试验了一下,结果发现nginx是完全支持.htaccess文件的! 方法如下: 1. 在需要使用.htaccess文件的目录下新建一个.htaccess文件, ...
Apache的Mode Rewrite模块和.htaccess文件配合.docx
mac电脑在xampp环境下搭建drupal使用的.htaccess配置文件,下载后将文件名改为.htaccess放在网站根目录即可。 如果网站不在根目录则放在对应级别的目录下 并修改htaccess文件119行和123行,将119行RewriteBase /...
zencart .htaccess
吧想要去除文件名的文件,拖动到去除文件名.bat上就可以得到空文件名的文件了。...应用范围(例如liux系统里面的控制文件.htaccess不能直接去除文件名造成了很大的麻烦,如果用上这个小工具就能很好的实现。)
设置网站路径,文件属性,页面404,403,以及域名重定向,
伪静态实现
到英文网站 才找到的 答案 (已译成中文)
如果你的服务器目录结构是这样: /usr/corsak/www/maindir 如果Apache指令中开启了AllowOverride支持.htaccess文件,每访问一次会依次搜索: /usr/corsak/www/maindir/.htaccess /usr/corsak/www/.htaccess /usr/...