Enhance your 404 page
-
The default 404 page doesn’t have much of value to offer a visitor that stumbles your website via an organic search result. This is why I have enhanced mine 404 page a bit and I would like to share that with you guys.
Add 301 redirect for 404 pages
Pages that have been removed to a different URL, will show a 404 page. Add a 301 redirect to your 404 page that will redirect the user to its new address.
Suppose you had an address domain/old-url this got moved to domain/new-address, add the follow code to your 404.php (located in your bb-templates folder). Add this to the top of the page.
<?php
$redirect_301 = array(
'/old-url/' => '/new-url',
'/another-old-url' => '/another-new-url'
);
$request = $_SERVER;
if (array_key_exists($_SERVER, $redirect_301)) {
header(“HTTP/1.1 301 Moved Permanently”);
header(‘Location: http://www.yourdomain.com’ . $redirect_301[$request] );
die();
}
?>
Also you can change the default text:
<p><?php _e('I'm sorry, but there is nothing at this URL.'); ?></p>
Into something more nice, like:
<p><?php _e('The page you are looking for can not be found or it has been removed. You can always just browse the website or even use the search form below to try another search.'); ?></p>
<?php search_form(); ?>
What do you guys think?
- You must be logged in to reply to this topic.