• Hi,
    How is it possible instead of getting a “page not found” message when trying to access a missing or wrong page that you will automatically be forwarded to the homepage?

Viewing 4 replies - 1 through 4 (of 4 total)
  • This appears to work.

    Put this code just before
    get_header();
    in your theme’s 404.php file.

    $home_url = get_bloginfo('url');
    header("Location: $home_url");
    Thread Starter enigma2k

    (@enigma2k)

    thank you, it is working!
    does this affect the search engines in any way?

    This sends a 404 (page not found) header before redirecting to home, so a search engine will know the URL doesn’t exist.

    $home_url = get_bloginfo('url');
    header("HTTP/1.x 404 Not Found");
    header("Location: $home_url");
    Thread Starter enigma2k

    (@enigma2k)

    thank you…using your “new” code now!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘redirect to homepage if page does not exist’ is closed to new replies.