WordPress Error 404 Primer Tutorial

WordPress Error 404 Primer Tutorial

WordPress Error 404 Primer Tutorial

It’s natural the preparing of a tutorial like yesterday’s Animated GIF Creator Video Intranet Tutorial could turn a person’s attention to the Internet HTTP Protocol’s …


Error 404 ... page not found or file not found

… no doubt the error that occurs most often on the net.

There are mechanisms in Apache web servers to cater for that eventuality. Webpages called 404.html or 404.htm or 404.php, typically, can be called into play to intervene at the point where the web browser encounters a webpage URL that is not found.

In our WordPress Blog we have in the Twenty Ten theme’s folder’s 404.php to play that role for us.

Today we add

<?php

/**
* The template for displaying 404 pages (Not Found).
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/

$uparts=explode("/", $_SERVER['REQUEST_URI']);
if (sizeof($uparts) >= 2) {
if (str_replace("category","cat",strtolower($uparts[-2 + sizeof($uparts)])) == "cat" || strtolower($uparts[-2 + sizeof($uparts)]) == "category") {
$catsare=["","Not Categorised","Ajax","Android","Animation","Anything You Like","Code::Blocks","Colour Matching","Data Integration","Database","Delphi","Eclipse","eLearning","ESL","Event-Driven Programming","Games","GIMP","GUI","Hradware","Installers","iOS","Land Surveying","Moodle","Music Poll","NetBeans","Networking","News","ontop","OOP","Operating System","Photography","Projects","Signage Poll","Software","SpectroPhotometer","Tiki Wiki","Trips","Tutorials","Uncategorized","Visual Studio","Xcode"];
for ($ibh=1; $ibh<sizeof($catsare); $ibh++) {
if (explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0] == strtolower($catsare[$ibh])) {
if (strtolower($catsare[$ibh]) == "ontop") {
header('Location: https://www.rjmprogramming.com.au/ITblog/category/' . str_replace(" ","-",explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;
} else {
header('Location: https://www.rjmprogramming.com.au/ITblog/category/' . str_replace(" ","-",explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;
}
} else if (explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0] == ('' . $ibh)) {
if (strtolower($catsare[$ibh]) == "ontop") {
header('Location: https://www.rjmprogramming.com.au/ITblog/?cat=' . str_replace(" ","-",explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;
} else {
header('Location: https://www.rjmprogramming.com.au/ITblog/?cat=' . str_replace(" ","-",explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;
}
}
}
}
}

get_header(); ?>

<div id="container">
<div id="content" role="main">

<div id="post-0" class="post error404 not-found">
<h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
<div class="entry-content">
<p><?php _e( 'Apologies, but the ' . $_SERVER['REQUEST_URI'] . ' page you requested could not be found. Perhaps searching will help.', 'twentyten' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</div><!-- #post-0 -->

</div><!-- #content -->
</div><!-- #container -->
<script type="text/javascript">
// focus on search field after it has loaded
document.getElementById('s') && document.getElementById('s').focus();
</script>

<?php get_footer(); ?>

… into the mix. The beauty of the WordPress codex software architecture is that is often assembled in this self explanatory manner. You can tell that with the …


get_header(); ?>

… it is a red rag to a bull that nothing has been written to the webpage up above this, leaving us free to write some code, and perhaps redirect with codelines such as …


header('Location: https://www.rjmprogramming.com.au/ITblog/category/' . str_replace(" ","-",explode("&",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;

… with no harm done, and we hope, given we try to be useful (and use PHP’s $_SERVER[‘REQUEST_URI’] as the indicator of the URL parts to the right of the domain name (ie. the bits after “rjmprogramming.com.au” in the WordPress Blog URL of interest)), and useful redirect to have less …


Error 404 ... page not found or file not found

… happening in the Internet woooooorrrrrllllllddd!

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>