Tips Of All Sorts

 
Want more Tips? Let us send you some for FREE!
First Name :
Last Name :
Email :

Non-Existent URLs Don’t Redirect To Custom 404 Page

May 16th, 2007

If your blog situation is exactly what has been described below (from nos. 1 to 5) , use the solution indicated at the bottom :

  1. When a fake url like www.tipsofallsorts.com/abcdefgh is entered, the custom 404.php that is found in the active theme folder refuses to show up, instead it is being redirected to the template belonging to page.php.
  2. Your permalink custom structure is : /%category%/%postname%/
  3. The fake url page gives a 200 status.
  4. < ?php header("HTTP/1.1 404 Not Found"); ?> has been included before < ?php get_header(); ?> in error.php.
  5. You have deactivated all the plugins and then reactivated them one by one but found none of them were giving problems. The Ultimate Tag Warrior (UTW) could disrupt permalinks.
  6. The .htaccess file reads :
    DirectoryIndex index.php index.html
    AddType text/x-server-parsed-html .html .htm
    ErrorDocument 404 /index.php?error=404

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php
    # END WordPress

SOLUTION
Add this to the top of single.php, page.php or category.php right above < ?php get_header(); ?> :

< ?php if (!have_posts()) { include(get_404_template()); exit; } ?>

This thread from the Wordpress support forum provided the solution :
http://wordpress.org/support/topic/99239

More helpful information :
http://wordpress.org/support/topic/93890
http://codex.wordpress.org/Permalinks

  Subscribe to my RSS feed for regular updates.