Support » Plugins » 404 redirects to search function

  • Hei there, I am currently looking to redirect 404 errors to the WordPress search function in order to present actual blog entries rather than the normal 404 Error.

    However, I am not really a PHP hacker but found some nice code I could use:

    <h2 class=”center”>Error 404 – Not Found</h2><?
    $search_term = substr($_SERVER[‘REQUEST_URI’],1);
    $search_term = urldecode(stripslashes($search_term));
    $search_url = get_bloginfo(‘url’) . index.php?s=;
    $full_search_url = $search_url . $search_term;
    $full_search_url = preg_replace(‘/ /’, ‘%20’, $full_search_url);
    $full_page = implode(“”, file($full_search_url));
    print_r($full_page); die();
    ?>

    The line 8 which says:
    search_url = get_bloginfo(‘url’) . index.php?s=;
    is definately wrong.

    I know this is just a minor PHP syntax error that can easily be corrected!

    Does someone here know the correct syntax? I’d appreciate your help a lot as this is giving me headaches right now 🙂

  • The topic ‘404 redirects to search function’ is closed to new replies.