I’d like to know this one too!
Hi,
Set your desired permalink and add this code in htaccess:
`# BEGIN WordPress
<IfModule mod_rewrite.c>
ErrorDocument 404 /index.php?error=404
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress`
Thanks,
Shane G.
Hi Shane, it seems you’ve missed the point of the OP. He wants to throw 404 instead of echoing “Not Found” in the template’s “Else” case.
From what I’ve seen so far, it looks like this can only be done at the top of the template before any whitespace and before get_header(). The template has to call has_posts() and then handle the 404 manually by setting headers, including other templates, and quitting the script.
For example, at the top of archive.php, get rid of this:
<?php get_header(); ?>
Replace with this:
<?php
if (!have_posts()) {
header("HTTP/1.0 404 Not Found - Archive Empty");
require TEMPLATEPATH.'/404.php';
exit;
}
get_header();
?>
NOW you have proper SEO. It’s shocking to see the WordPress core miss things like that.
This works a little better:
<?php
if (!have_posts()) {
header("HTTP/1.0 404 Not Found - Archive Empty");
$wp_query->set_404();
require TEMPLATEPATH.'/404.php';
exit;
}
get_header();
?>
miqrogroove
Yes, you are absolutely correct. We use it like this:
if(have_posts())
{
.. do something
}
else
{
include(TEMPLATEPATH . ‘/404.php’);
}