Where does the 404 redirection happen?

Can someone please tell me where the 404 redirection occurs?

I am wanting to redirect to a custom template.php instead of the 404 page.

Read More

Is this possible to do? If it is can some one provide me with a solution.

Thanks
Ravi

Related posts

Leave a Reply

4 comments

  1. Based on your comments, I think I get what you’re saying. However, you don’t want to redirect on a 404, since it defeats the object of the ‘Not Found’ header.

    However, you can filter the 404 template path and pass back your own;

    function __custom_404( $standard_404 )
    {
        if ( something_is_true() )
            return '/absolute/path/to/custom.php';
        return $standard_404;
    }
    add_filter( '404_template', '__custom_404' );
    
  2. Going off of TheDeadMedic you can try this:

    Not 100% that this will work

    function wpse_20157_404( $standard_404 ) {  
        if ( is_single() || is_tag('whatever','product' && is_404()) ) // Use || to list multiple if's
            include_wordpress_template(TEMPLATEPATH . '/custom404.php');
    }
    add_action( 'template_redirect', 'wpse_20157_404' );
    

    Or my original answer

    function wpse_20157_404( $standard_404 ) {  
        if ( is_single() || is_tag('whatever','product') ) // Use || to list multiple if's
            include_wordpress_template(TEMPLATEPATH . '/custom404.php');
    }
    add_filter( '404_template', 'wpse_20157_404' );
    
  3. Since 404’s happen at the server the best way to redirect a 404 away from WordPress’ 404.php is by adding this to the .htaccess file at your site root.

      ErrorDocument 404 /relative/path/to/404page
    

    This must be a relative path, not an absolute path.