Prevent Soft 404 and force a HARD 404 header response
-
Hi there,
I have a 404.php template within my theme, and within that it simply echo’s out ‘404’ with some simple php. Pretty simple.
Importantly in the header.php of my theme I use the following php code
to pull the 404 page when needed.<?php if (!have_posts()) { header("HTTP/1.0 404 Not Found"); $wp_query->set_404(); require TEMPLATEPATH.'/404.php'; exit; } else{ LOADS NORMAL HEADER STUFF HERE } ?>
Weirdly this works in as much as the logic kicks in and the 404 page loads when expected and when doesn’t load when it is not needed so that’s all good, but when checking the header response through google webmaster tools and others like webconfs.com it shows as a 302 FOUND for pages that simply don’t exist!!
Frustrating as I want to return HARD 404 responses not a SOFT 404 to Google. Has anyone else dealt with this before? Quite an annoying SEO oversight.
Many thanks in advance as always!
Bowser
- The topic ‘Prevent Soft 404 and force a HARD 404 header response’ is closed to new replies.