PDA

View Full Version : create a custom 404 error document



texasgamer
05-08-2008, 09:07 PM
Error 404 - This means that the URL that a visitor typed does not exist.
If the page does not exist, the person leaves and continues surfing somewhere else. You should always try to redirect the visitor back to a page on your website that is active (like your main page). No sense in loosing a potential customer!

To redirect a person back to your website, you need to create two text files. First create a new text document. Open it with your favorite text editor (notepad) and add this one line of text:

ErrorDocument 404 /404.html

Close the file, and save as ".htaccess" (without the quotes).

Next we need to create a basic 404.html page. Open up your favorite text editor again (notepad) and add this text:

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd (http://www.wapforum.org/DTD/xhtml-mobile10.dtd)">
<html xmlns="http://www.w3.org/1999/xhtml (http://www.w3.org/1999/xhtml)">
<head>
<title>404 Not Found</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> </head>
<body>
<h1>404 Not Found</h1>
<p>Uh Oh! Whatever you were looking for either does not exist or was moved.</p>
<p>Go directly to <a href="http://www.NameOfYourSite.mobi</a> now.</p>
</body>
</html>

You need to replace http://www.NameOfYourSite.mobi with the name of your site that your working on.
Close this file, and save as "404.html" (without the quotes).

You can make your custom 404 error html page say anything you want. You edit or add to the html page as you wish. Ususally you want to direct the person back to your main website page, but its up to you. You can send them anywhere you wish, even to another site!

Next upload the ".htaccess" file and the custom 404 error page (404.html) to your server. You want to put these files inside the folder (directory) of the name of your site. It goes where you put your index.html or index.php file for the site that your working on.

Some sites will already have an .htaccess file. If this is the case, what I do is download it and open it with notepad. If its blank then I just add the one line of text. If there is other commands already there, I just add the one line of text on the next row. Save and re-upload to you server.

Your done!

Test your custom 404.html file by accessing a page that does not exist.
Here is an example:
www.namebook.mobi/thispagedoesnotexist.html (http://www.namebook.mobi/thispagedoesnotexist.html)

You should see your custom 404.html file!

Here are some html error codes
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy
400 Bad Request
401 Unauthorized (directory is protected by a password)
402 Payment Required
403 forbidden (all visitors are barred from looking at this file or directory)
404 file not found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Time-Out
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Large
415 Unsupported Media Type
500 internal server error (cgi script error)
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Time-Out
505 HTTP Version Not Supported

Hope this little tut helps. Its geared towards beginners....:adore:

coast
05-08-2008, 09:23 PM
Amazing Texasgamer - thank you so much! I will be back when I can rep you (I used up my three, wahhhhhh!)

bricio
05-08-2008, 09:27 PM
thanks for posting this texasgamer!!!

repped

texasgamer
05-08-2008, 09:38 PM
Here is what you add to the .htaccess file for a 301 redirect:

redirect 301 old/old.html
http://www.yoursite.com/new.html

NOTE: Don't add "http://www" to the first line - place the path from the top level of your site to the page.

rob
05-09-2008, 02:35 AM
tip: this has to go in the first line of your .htaccess file and to use a proper text editor to edit the file... upload the file in ascii mode via ftp.

GijsZePa
05-09-2008, 06:24 AM
Well..

You can more than you think with an 404 page. Check this article (http://www.alistapart.com/articles/perfect404/) and be suprised :)

Martin