{"id":53868,"date":"2021-11-10T03:01:41","date_gmt":"2021-11-09T17:01:41","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=53868"},"modified":"2021-11-10T05:49:44","modified_gmt":"2021-11-09T19:49:44","slug":"wordpress-error-404-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-error-404-primer-tutorial\/","title":{"rendered":"WordPress Error 404 Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/category\/photography\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"WordPress Error 404 Primer Tutorial\" src=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp_404.jpg\" title=\"WordPress Error 404 Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">WordPress Error 404 Primer Tutorial<\/p><\/div>\n<p>It&#8217;s natural the preparing of a tutorial like yesterday&#8217;s <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/animated-gif-creator-video-intranet-tutorial\/' title='Animated GIF Creator Video Intranet Tutorial'>Animated GIF Creator Video Intranet Tutorial<\/a> could turn a person&#8217;s attention to the Internet HTTP Protocol&#8217;s &#8230;<\/p>\n<p><code><br \/>\nError 404 ... page not found or file not found<br \/>\n<\/code><\/p>\n<p> &#8230; no doubt the error that occurs most often on the net.<\/p>\n<p>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.<\/p>\n<p>In our <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog' title='This blog'>WordPress Blog<\/a> we have in the Twenty Ten theme&#8217;s folder&#8217;s 404.php to play that role for us.<\/p>\n<p>Today <font color=blue>we add<\/font> &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n\/**<br \/>\n * The template for displaying 404 pages (Not Found).<br \/>\n *<br \/>\n * @package WordPress<br \/>\n * @subpackage Twenty_Ten<br \/>\n * @since Twenty Ten 1.0<br \/>\n *\/<br \/>\n<font color=blue><br \/>\n$uparts=explode(\"\/\", $_SERVER['REQUEST_URI']);<br \/>\nif (sizeof($uparts) &gt;= 2) {<br \/>\n  if (str_replace(\"category\",\"cat\",strtolower($uparts[-2 + sizeof($uparts)])) == \"cat\" || strtolower($uparts[-2 + sizeof($uparts)]) == \"category\") {<br \/>\n    $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\"];<br \/>\n    for ($ibh=1; $ibh&lt;sizeof($catsare); $ibh++) {<br \/>\n      if (explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0] == strtolower($catsare[$ibh])) {<br \/>\n        if (strtolower($catsare[$ibh]) == \"ontop\") {<br \/>\n          header('Location: https:\/\/www.rjmprogramming.com.au\/ITblog\/category\/' . str_replace(\" \",\"-\",explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;<br \/>\n        } else {<br \/>\n          header('Location: https:\/\/www.rjmprogramming.com.au\/ITblog\/category\/' . str_replace(\" \",\"-\",explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;<br \/>\n        }<br \/>\n      } else if (explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0] == ('' . $ibh)) {<br \/>\n        if (strtolower($catsare[$ibh]) == \"ontop\") {<br \/>\n          header('Location: https:\/\/www.rjmprogramming.com.au\/ITblog\/?cat=' . str_replace(\" \",\"-\",explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;<br \/>\n        } else {<br \/>\n          header('Location: https:\/\/www.rjmprogramming.com.au\/ITblog\/?cat=' . str_replace(\" \",\"-\",explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;<br \/>\n        }<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n}<br \/>\n<\/font><br \/>\nget_header(); ?&gt;<br \/>\n<br \/>\n\t&lt;div id=\"container\"&gt;<br \/>\n\t\t&lt;div id=\"content\" role=\"main\"&gt;<br \/>\n<br \/>\n\t\t\t&lt;div id=\"post-0\" class=\"post error404 not-found\"&gt;<br \/>\n\t\t\t\t&lt;h1 class=\"entry-title\"&gt;&lt;?php _e( 'Not Found', 'twentyten' ); ?&gt;&lt;\/h1&gt;<br \/>\n\t\t\t\t&lt;div class=\"entry-content\"&gt;<br \/>\n\t\t\t\t\t&lt;p&gt;&lt;?php _e( 'Apologies, but the <font color=blue>' . $_SERVER['REQUEST_URI'] . ' <\/font>page you requested could not be found. Perhaps searching will help.', 'twentyten' ); ?&gt;&lt;\/p&gt;<br \/>\n\t\t\t\t\t&lt;?php get_search_form(); ?&gt;<br \/>\n\t\t\t\t&lt;\/div&gt;&lt;!-- .entry-content --&gt;<br \/>\n\t\t\t&lt;\/div&gt;&lt;!-- #post-0 --&gt;<br \/>\n<br \/>\n\t\t&lt;\/div&gt;&lt;!-- #content --&gt;<br \/>\n\t&lt;\/div&gt;&lt;!-- #container --&gt;<br \/>\n\t&lt;script type=\"text\/javascript\"&gt;<br \/>\n\t\t\/\/ focus on search field after it has loaded<br \/>\n\t\tdocument.getElementById('s') && document.getElementById('s').focus();<br \/>\n\t&lt;\/script&gt;<br \/>\n<br \/>\n&lt;?php get_footer(); ?&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; into the mix.  The beauty of the WordPress <a target=_blank href='https:\/\/codex.wordpress.org\/Main_Page' title='WordPress codex'>codex<\/a> software architecture is that is often assembled in this self explanatory manner.  You can tell that with the &#8230;<\/p>\n<p><code><br \/>\nget_header(); ?&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; 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 &#8230;<\/p>\n<p><code><br \/>\n          header('Location: https:\/\/www.rjmprogramming.com.au\/ITblog\/category\/' . str_replace(\" \",\"-\",explode(\"&\",strtolower($uparts[-1 + sizeof($uparts)]))[0])) . '#' . $ibh;<br \/>\n<\/code><\/p>\n<p> &#8230; with no harm done, and we hope, given we try to be useful (and use PHP&#8217;s $_SERVER[&#8216;REQUEST_URI&#8217;] as the indicator of the URL parts to the right of the domain name (ie. the bits after &#8220;rjmprogramming.com.au&#8221; in the WordPress Blog URL of interest)), and useful redirect to have less &#8230;<\/p>\n<p><code><br \/>\nError 404 ... page not found or file not found<br \/>\n<\/code><\/p>\n<p> &#8230; happening in the Internet woooooorrrrrllllllddd!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d53868' onclick='var dv=document.getElementById(\"d53868\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/redirect\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d53868' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s natural the preparing of a tutorial like yesterday&#8217;s Animated GIF Creator Video Intranet Tutorial could turn a person&#8217;s attention to the Internet HTTP Protocol&#8217;s &#8230; Error 404 &#8230; page not found or file not found &#8230; no doubt the &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-error-404-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[3851,3848,3849,1669,85,151,1887,1929,581,621,2355,899,932,997,1035,1319,3850,1324,1345,1418,1456],"class_list":["post-53868","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-_serverrequest_uri","tag-3848","tag-404-php","tag-address-bar","tag-apache","tag-blog","tag-codex","tag-error","tag-http","tag-internet","tag-not-found","tag-parse","tag-php","tag-programming","tag-redirect","tag-tutorial","tag-twenty-ten-theme","tag-twentyten","tag-url","tag-webpage","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/53868"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=53868"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/53868\/revisions"}],"predecessor-version":[{"id":53875,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/53868\/revisions\/53875"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=53868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=53868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=53868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}