From 111d7005e61f995cb1fa7dde4c340f61787be328 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 10 Nov 2004 04:01:46 +0000 Subject: [PATCH] Issue a 404 if a permalink request does not match any posts. git-svn-id: https://develop.svn.wordpress.org/trunk@1850 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-blog-header.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wp-blog-header.php b/wp-blog-header.php index e72e8dc76e..b82a8cac4f 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -184,6 +184,16 @@ if (1 == count($posts)) { } } +// Issue a 404 if a permalink request doesn't match any posts. Don't issue a +// 404 if one was already issued, if the request was a search, or if the +// request was a regular query string request rather than a permalink request. +if ( (0 == count($posts)) && !is_404() && !is_search() + && !empty($_SERVER['QUERY_STRING']) && + (false === strpos($_SERVER['REQUEST_URI'], '?')) ) { + $wp_query->is_404 = true; + header("HTTP/1.x 404 Not Found"); +} + $wp_did_header = true; endif;