A 404 occurs when a file on your webserver is called on by a referring application. Essentially it just means that the file that was called on cannot be found.
From HTTP status code #404, “Not Found,” specified by RFC 2616 (Hypertext Transfer Protocol, Network Working Group).
Before we begin, there are a few things to know or that you might want to know.
1 2 3 | <?php get_header(); ?> <h1>404 - File Not Found.</h1> <?php get_footer(); ?> |
1 2 3 4 5 6 | <?php get_header(); ?> <div id="content" class="narrowcolumn"> <h2 class="center">Error 404 - Not Found</h2> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> |
Let’s disect this code really quickly..
1 2 3 4 | <?php if (is_404()) { ?> <meta http-equiv="refresh" content="15;URL=http://www.junglejar.com"> <?php } ?> |
1 2 3 4 5 | <?php if (is_404()) { $redirectHome = get_option('home'); ?> <meta http-equiv="refresh" content="15;URL=<?php echo $redirectHome; ?>"> <?php } ?> |
Both examples above will re-direct our users to a different page when a 404 error is issued by the web server. Let’s analyze the code…
1 2 3 4 5 6 7 8 9 | <meta name="description" content="JungleJar offers articles, tutorials, rss feeds, tips and strategies, free Wordpress templates, among many other things to assist webmasters with their respective websites." /> <?php if (is_404()) { $redirectHome = get_option('home'); ?> <meta http-equiv="refresh" content="15;URL=<?php echo $redirectHome; ?>"> <?php } ?> <meta name="robots" content="index,follow" /> |
Of course this is not my entire header.php file, but it shows how I added in the snippet in between other meta tags.
Below is an example of how I might edit my 404.php file to somehow let the user know they will soon be re-directed..
1 2 3 4 | <?php get_header(); ?> <h1>404 - File Not Found.</h1> <h3>Please <a href="<?php bloginfo('home'); ?>">Click here</a> to go to the main index or simply wait 15 seconds..</a></h3> <?php get_footer(); ?> |
If you’re feeling frisky, you might consider using Google.com’s AJAX Search API on your 404 page.