| How do I get a custom 404 Error Page? |
|
|
|
Creating an Error 404 PageWhile you work hard to make sure that every link actually goes to a specific web page on your site, there is always a chance that a link clicked will slam dunk and become a famous 404 ERROR PAGE NOT FOUND. All is not lost. If your visitors encounter an error, why not be a helpful WordPress site administrator and present them with a message more useful than "NOT FOUND". This lesson will teach you how to edit your "error" and "page not found" messages so they are more helpful to your visitors. We'll also show how to ensure your web server displays your helpful custom messages. Finally, we'll go over how to create a custom error page consistent with your Theme's style.
An Ounce of PreventionSome errors are avoidable, you should regularly check and double check all your links. Also, if you are deleting a popular but out-of-date post, consider deleting the body of the post, and replacing it with a link referring visitors to the new page. Understanding Web Error HandlingVisitors encounter errors at even the best web sites. As site administrator, you may delete out-of-date posts, but another web site may have a link to your inside page for that post. When a user clicks on a link to a missing page, the web server will send the user an error message such as 404 Not Found. Unless your webmaster has already written custom error messages, the standard message will be in plain text and that leaves the users feeling a bit lost. Most users are quite capable of hitting the back key, but then you've lost a visitor who may not care to waste their time hunting for the information. So as not to lose that visitor, at the very least, you'll want your custom message to provide a link to your home page. The friendly way to handle errors is to acknowledge the error and help them find their way. This involves creating a custom Error Page or editing the one that came with your WordPress Theme. Editing an Error 404 PageThe default WordPress theme has a 404.php file, but not all Themes have their own custom 404 error template file. If they do, it will be named 404.php. WordPress will automatically use that page if a Page Not Found error occurs. The normal 404.php page shipped with your Theme will work, but does it say what you want it to say, and does it offer the kind of help you want it to offer? If the answer is no, you will want to customize the message in the template file. To edit your Theme's 404 error template file:
While you are examining and editing your 404 template file, take a look at the simple structure of the default 404.php file. It basically features tags that display the header, sidebar, and footer, and also an area for your message: <?php get_header(); ?> So, to change the error message your visitor sees, revise the text within the h2 heading and if necessary, add more paragraphs below that. Creating an Error 404 PageIf your WordPress Theme does not include a template file named 404.php, you can create your own. Because every theme is different, there is no guarantee that copying over the 404.php template file found in the WordPress Default Theme will work, but it's a good place to start. The error page you copy from the Default Theme will adopt the style of the current theme because it actually calls the header and footer of the current theme. That's less work for you, and you may only have to edit the message to suit your particular needs. To use the 404.php template file from the WordPress Default Theme:
If copying the default 404.php into your theme directory does not work well with your theme, you have some other choices:
Or
Advanced 404.php ExampleThis is an example of some of the technical capabilities of WordPress 404.php and HTTP Status Code Handling. You should strive to make your 404 error pages as helpful to your site visitors as you can, and when possible you should redirect broken URI's to the correct resource. The AskApache Google 404 Plugin shows how to handle other types of error status codes that may be handled by your "404.php" template file. This helps to determine the type of server error so that you can provide the correct http response without wasting bandwidth and CPU for non-404 errors. It tries to issue the correct response using HTTP status codes and the specifications compatible with RFC 2616 specifications. <?php Tips for Error PagesThere are various improvements you can make to your 404 Error web pages so let's look at some of your options. Sending Proper HeadersBy default, WordPress continues to send 404 pages as if they were fine. To make search engines like Google spider these pages correctly, you can add this line to the top of your theme's 404.php file. Note: This is no longer required in the latest versions of Wordpress <?php header("HTTP/1.1 404 Not Found"); ?>
You may have to add this before the above code in some cases. <?php ob_start(); ?> Writing Friendly MessagesWhen an error message is displayed, you can say many things to help a visitor feel reassured they've only encountered a minor glitch, and you're doing the best you can to help them find the information they want. You can say something clever like: "Oops, I screwed up and you discovered my fatal flaw. You should also attempt to show the user what they want. Check out the AskApache Google 404 Plugin to add google search results to your 404.php Or, say something shorter and sweeter. Almost anything you say is better than 404 Error Page Not Found. You can find more information about writing 404 Error pages on the Internet, like List Apart's Perfect 404. As an implementation of the Perfect 404 page, this solution will tell the user it's not their fault, if it isn't and email the webmaster, according to WordPress's database. Helpful 404 page When a visitor gets a 404 error page, it can be intimidating, and unhelpful. Using Wordpress, you can take the edge off a 404 and make it helpful to users, and yourself, too, by emailing whenever the user clicks a link to a non-existent page. <p>You Add Useful LinksIf you encounter a "page not found" situation on the WordPress site, it is filled with helpful links to direct you to the various categories and areas of information within the WordPress site. To add similar useful links to your 404 page, create a list, or a paragraph, so the visitor can easily determine which section might be useful to visit. Information of that nature is much better than having the user just reach a dead-end. To help you understand how to link to documents within your site, especially to Pages and Categories, see Linking_Posts_Pages_and_Categories. Testing 404 Error MessagesTo test your custom 404 page and message, just type an URL address into your browser for your website that doesn't exist. Make one up or use something like: http://example.com/fred.php This is sure to result in an error unless you actually have a php file called fred. If your error page doesn't look "right", you can go back and edit it so it works correctly and matches your Theme's look and feel. Help Your Server Find the 404 PageBy default, if WordPress cannot find a particular page it will look for the 404.php web page. However, there may be cases where the web server encounters a problem before WordPress is aware of it. In that case, you can still guarantee that your web server sends the visitor to your 404.php template file by configuring your web server for custom 404 error handling. To tell your web server to use your custom error files, you'll need to edit the .htaccess file in the main directory (where main index.php file resides) of your WordPress installation. If you don't have an .htaccess file, see Editing Rewrite Rules (.htaccess) on how to create an .htaccess file. To ensure the server finds your 404 page, add the following line to your ErrorDocument 404 /index.php?error=404 The url /index.php is root-relative, which means that the forward slash begins with the root folder of your site. If WordPress is in a subfolder or subdirectory of your site's root folder named 'wordpress', the line you add to your .htaccess file might be: ErrorDocument 404 /wordpress/index.php?error=404
Additional Error Code Handling
Please try to use as many static errordocuments as you can, as a single /missing.html file being server for a missing image (404 Not Found) would take up incredibly less CPU and Memory than having it processed by /index.php?error=404 To enable your WordPress 404.php template file to handle additional server errors, you can use something like this in your .htaccess file. Notice how some errors are handled by WordPress, while other errors output a static .html document, and a few are actual php scripts. For instance, a 500 error would not be suitable to be handled by WordPress, as the 500 error could be occuring due to WordPress, like a bad plugin. So by instructing your server to instead serve a static .html document you can display a much more helpful error message to your visitors. ErrorDocument 400 /cgi-bin/error-deal.php Questions About Error Files
Other Error NumbersHere are more standard web error numbers. You can see the headers and output at Apache Status Codes and ErrorDocuments
|
New Joomla Templates
Social ConnectedName: Social ConnectedDescription: Social Connected is a new professional, easy to use Joomla template released by the Joomladesigns team which includes custom CSS style layouts for the Jomsocial and K2 Extensions. The Social Connected template includes the following features Three Jooml ...Owner: JoomlaDesignsTags: Computers, Communications, Business, Architecture
ExtendName: ExtendDescription: Extend is a professional easy to use Joomla template released by the Joomladesigns Team. The new Extend template supports the following features Includes Four different Joomla Templates Built-in colour picker to customize the template colour scheme Bui ...Owner: JoomlaDesignsTags: Business, Beauty, Architecture
NgineName: NgineDescription: Ngine is a new professional Joomla template from Joomladesigns.co.uk which supports a wide range of features including Five built-in Joomla templates Slide show Slide pop up boxes K2 CSS styles RTL support Six built in font styles Lots of module posi ...Owner: JoomlaDesignsTags: Software, Portal, News, Games
Simply City 2Name: Simply City 2Description: Simply City is a professional, fast loading Joomla template which is easy to use and includes a wide range of features. The web design also supports CSS styles for the popular K2 extension. The Joomla template includes the following features 3 multi col ...Owner: JoomlaDesignsTags: Computers, Communications, Business
Simply CityName: Simply CityDescription: Simply City is a professional, fast loading Joomla template which is easy to use and includes a wide range of features. The web design also supports CSS styles for the popular K2 extension. The Joomla template includes the following features 3 different ...Owner: JoomlaDesignsTags: Electronics, Computers, Communications, Business- Show more...







