fix-404-pages-redirect

If you have ever deleted a page in WordPress and noticed that its old “pretty URL” does not return a 404, but instead redirects to the homepage, you are not alone.

This is a well-known WordPress behavior that frequently causes confusion—and worse, SEO problems. In this article, we will explain:

  • Why WordPress behaves this way

  • Why redirecting deleted URLs to the homepage is a bad idea

  • How to force WordPress to return real 404 errors

  • Best practices for handling deleted content correctly


The Problem: Deleted Pages Redirect to Homepage

Scenario:

  1. You delete a page or post in WordPress.

  2. You visit its old URL, for example:

https://example.com/about-old/
  1. Instead of seeing a 404 page, WordPress:

    • Redirects to /

    • Returns HTTP 200

    • Or performs a silent canonical redirect

This creates what search engines call a soft 404.


Why This Happens in WordPress

This behavior is not a bug, but a consequence of how WordPress resolves URLs.

1. WordPress Rewrite & Query Resolution

When a request comes in, WordPress:

  1. Matches the URL against rewrite rules

  2. Tries to resolve it as:

    • A page

    • A post

    • A taxonomy

    • A fallback query

  3. If nothing matches cleanly, WordPress may treat the request as the front page query

Result: homepage content with a 200 OK response.


2. Canonical Redirects (redirect_canonical())

WordPress uses redirect_canonical() to “fix” URLs it thinks are invalid or malformed.

In many cases, this function:

  • Assumes the URL should resolve somewhere

  • Redirects unknown slugs to the homepage


3. Theme or Plugin Interference (Very Common)

Many themes or plugins contain logic similar to:

if ( ! have_posts() ) {
wp_redirect( home_url() );
exit;
}

This is incorrect behavior and silently converts real 404s into homepage redirects.

SEO plugins and page builders are frequent culprits.


Why This Is Bad for SEO

Redirecting deleted content to the homepage causes:

  • Soft 404s in Google Search Console

  • Index bloat

  • Loss of crawl budget

  • Poor user experience

  • Lower trust signals for your domain

Google explicitly recommends returning a real 404 when content no longer exists and has no replacement.


How to Fix It: Force Proper 404 Responses

✅ Solution 1 (Recommended): Disable Canonical Redirects for 404s

Add this snippet to functions.php or a small custom plugin:

add_filter( 'redirect_canonical', function ( $redirect_url ) {
if ( is_404() ) {
return false;
}
return $redirect_url;
});

This prevents WordPress from auto-redirecting missing URLs.


✅ Solution 2: Force 404 When No Posts Are Found

This ensures deleted slugs always return a real 404 response.

add_action( 'template_redirect', function () {
if ( is_main_query() && ! have_posts() && ! is_home() && ! is_front_page() ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
include get_404_template();
exit;
}
});

✅ Solution 3: Handle Deleted Pages Explicitly

If the issue mainly affects pages (not posts):

add_action( 'template_redirect', function () {
if ( is_page() && ! get_queried_object() ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
include get_404_template();
exit;
}
});

Check Your Theme (Critical Step)

Before adding code, inspect your theme for:

  • wp_redirect( home_url() )

  • template_redirect hooks

  • pre_get_posts filters

Any redirect triggered on ! have_posts() should be removed.

This is the number one hidden cause of homepage redirects.


How to Verify the Fix

Run:

curl -I https://example.com/deleted-page/

Correct response:

HTTP/2 404

Incorrect responses:

HTTP/2 301 → /
HTTP/2 200

Best Practice for Deleted Content

Situation Correct HTTP Status
Deleted content, no replacement 404
Deleted content with new equivalent 301 redirect
Temporarily unavailable 503
Mistyped or invalid URL 404

Redirecting everything to the homepage is never recommended.


Conclusion

  • This is a known WordPress behavior

  • Homepage redirects for deleted URLs are wrong

  • Proper 404 handling improves SEO and UX

  • The fix is straightforward and safe when implemented correctly

If you want a theme-safe, plugin-safe snippet tailored to your setup (theme name + SEO plugin), feel free to ask.

SHARE THIS POST

Leave a Reply