You are using a browser which is not compatible with CSS (for more information, see Tara's tutorial).
Because of this, it is possible that our website may not appear
correctly in your browser. We apologise for the inconvenience, and
recommend you upgrade your browser to one which is compatible with CSS.
For more information, please visit our Browser Upgrade page.
In order to have a complete understanding of what a .htaccess file is, I suggest that you also read our Control File Defaults tutorial and our Password Protection tutorial.
The .htaccess file is a file found in Apache servers that allows you to manipulate the behaviour of the server. A very common use is to create custom error messages for server errors. Examples of such errors are "404 Not Found" (say when you click on a broken link), and the "500 Internal Server Error" (a script failed). Most hosts allow you to have your own .htaccess file, and so now we will look at only one of the things we can do with a custom .htaccess.
Some quick notes before we start: under Windows, you cannot save a file with the name of ".htaccess". An easy trick is to create a file called htaccess.txt and edit that. Uploading of the file (regardless of its name) must be done in TEXT/ASCII mode (not BINARY). Finally, under Unix, any file that starts with a '.' is invisible, so when you upload your file, you may not see it. If you uploaded a file called htaccess.txt, just rename it to .htaccess using your FTP client.
What you can do with .htaccess is tell the server to display a special page to the user in case of an error. This page should, ideally, tell the user that something is wrong, down-play the fact that someone messed up (probably you as the webmaster!), and also provide a set of links to the major sections of the site, so the user can at least look for what is missing. Another nice use is to include a search form on the 404 page. You can also tell the server to run a CGI script, instead of simply displaying a static page. If you do this, you can tell the script to log the error for you, or the script can send you an email about the error.
So how do we implement this? Since the .htaccess file is a simple text file, you simply add a line of text to the file, one for each error you want to trap. The general format is:
ErrorDocument 3DigitErrorCode /path/to/your/error/file/or/script
The 3-Digits error codes are as follows:
Error 400 Bad Request
Error 401 Authorization Required
Error 403 Forbidden
Error 404 Missing
Error 500 Server Configuration Error
Thus the following line tells the server to run the error404.cgi script if the server cannot find the requested page.
ErrorDocument 404 /cgi-bin/error404.cgi
This way, you can trap as many errors as you want.
Below is an example of a .htaccess file, just copy and paste into your file, but change the paths:
ErrorDocument 404 /path/to/your/error/file/or/script
ErrorDocument 500 /path/to/your/error/file/or/script
ErrorDocument 403 /path/to/your/error/file/or/script
A very important point to note is that the paths should be the relative paths. This means that the paths would be what you would type on the machine to get to the files, not what you would type in the address box in a browser.
Examples:
Full path would be http://www.yoursite.com/path/to/error/page
Absolute path would be /home/yoursite.com/path/to/error/page
Relative path would be /path/to/error/page
To summarise the steps, they are as follows:
Now you are done!
As a final note, a good script to use for this task is the one at BigNoseBird. It is called Birdtrap.
Any troubles/comments please post at the Forums.
This tutorial is adapted from the article that first appeared at http://www.ekstreme.com.
© 4WebHelp and eKstreme
https://raunakgroup.com
http://www.hafoos.com
http://www.citizenumbrella.com
you are trying to access
www.example.com/.htaccess
and you have set ErrorDocument 404 /404.html
you will see your edited 404 but the http returns 403
you can check it here:
https://www.hurl.it/
To edit the 404 page, open up or create the site's .htaccess file. You can create it in a text editor and upload it to your site via the FTP server. Keep in mind that the name of the file has to be simply .htaccess.
Add the following line to the file, replacing new404.html with the correct new error page name:
ErrorDocument 404 /new404.html
http://www.vardhamaninfotech.com/?page_id=49
ErrorDocument 500 /500.php
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
ErrorDocument 401 /401.php
ErrorDocument 400 /400.php
it's ok for error 404/401/403...doesn't work for error 400/500...i get the server's answer
any tips?
thanks
Excellent post, went ahead and bookmarked your site. I can’t wait to read more from you.
rovided apparent thought
Having said that, I have made ErrorDocument work for normal html page, but I have yet to make it work for cgi scripts.
I seems to have some trouble get it to work, due to understanding issues since im pretty noobish i could really use further help (:
Here is the case:
In the root folder for my site, var/www i have created the .htaccess file, i think im soo wrong to the content, it ONLY contains this line:
ErrorDocument 404 /404-error-page.html
The 404-error-page.html is in the root folder with the .htaccess file also.
Thank you so much
-D-
http://www.holytraffic.com
It's really very useful tutorial for me. It helped me with lot of information. Which i was searching. Thanks you saved a lot of time.
VIP-Branchenbuch.de
I mean - taking somehow the link from which the user was taken to the 404 error page...
I tried with $_SERVER['HTTP_REFERER'] and didn't worked...
Chris
http://www.ThinKlear.net/
http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html
http://www.negative-seo.net
Plz. tell me the process of creating error document in html. I have used .htaccess but it is not secure. I am facing 404 and 403 error on my site.
We can create html error page in which we specify if 404 error encounter then go to this page and 403 error then go to that page, but i donot know that procedure plz. help me its urgent.
Rajkumar
(i have a script that emails me when they get the 404, i want it to nclude the page they tried accessing, so i can see where the problem is.)
ty
ErrorDocument 404 /customerror/error.php?errornumber=404
That would go in your httpd.conf file.
PS - Make sure that all of your links inside are not local. (Include the entire URL for images, CSS, ...)
-go figure.
Just add some "invisible" text in the html to fill it up.
I have different folders for many different websites I design and each has it's own .htaccess file.
The link in the .htaccess to your error pages is best made by stating the full URL e.g. http://www.yourwebsite.com/foldername/404.html
This is the easiest and least likely to have errors.
The only problem I havent figured out how to overcome is to make it work with links to PHP files.
When I use
ErrorDocument 401 /error.php
I lost the POST form data.
Is there any way of getting the POST form data in /error.php?
Where do I place the .htaccess file so that ONLY www.xnxnxn.com/bad-page-requested gets the hook?
Please reply to phone@yoda.com
thanks
Technische Probleme!!
in regards
Brendan
thankyou Brendan
se presenta cuando entro en el administrador de visitante
el error dice lo siguiente:
EN UNA VENTANA SALE:
MONITIR:Error[5]creating named fire
y seguido en otra ventana sale lo siguiente:
C Raid_boolApp::InitInstance:
Reg Createkey ex()failed.
acceso denegado
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
please help
<!--
comments here
-->
When you start your Windows 2000-based computer, you may receive the following error message:
System Process - Unable to Load Device Driver
\SystemRoot\System32\DRIVERS\ipsec.sys device driver could not be loaded.
Error Status was 0xc0000034.
CAUSE
and is placed in root, along with my webpages.
The 404.html is there also, resarted and same Not Found error is still there, I tried copying the .htaccess line in httpd.conf , and still the same.
Apache2 on xp pro and php.
Is there something else I need to configure in the httpd.conf file or elsewhere?
The main reason is that the default 404, 500, etc...shows my apache vs and info.
confused!
http://perso.wanadoo.es/gonzisp
FREE-NOT REGISTER
The path listed in the .htaccess file is relative to the root of the website, not relative to the .htaccess file. Thus, if I place the .htaccess file in
/somepath/public_html/test/.htaccess
/somepath/public_html/test/404.html
/somepath/public_html/index.html
ErrorDocument 404 404.html
and the rule
ErrorDocument 404 /404.html
The rule
ErrorDocument 404 somepath/public_html/test/404.html
http://website.com/somepath/public_html/test/404.html
The proper form is
ErrorDocument 404 /test/404.html
of course, this is true no matter where you put the .htaccess file.
and it wont work?
404 is in the same dir as .htaccess
plz help?
Add a new comment