WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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

Thanks Ravi

share|improve this question
Why not just use the 404.php template in your theme? – TheDeadMedic Jun 16 '11 at 9:00
i am using one product(our application).when i call the files(pages) from that it will automatically redirect to 404.php page.but i want to redirect to another PAGE. thats why i am asking. – Ravichandran Jothi Jun 16 '11 at 9:06
are you trying to redirect a tag group, post type, archive or what – xLRDxREVENGEx Jun 16 '11 at 23:58

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' );
share|improve this answer

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' );
share|improve this answer
Updated answer with a second solution – xLRDxREVENGEx Jun 17 '11 at 5:55

at the top of your 404.php add:

if ($_SERVER['HTTP_REFERER'] == "Whatever"){
share|improve this answer
ok..but it still executed in 404.php as per your code. I want the redirection does not goto 404.php ever and it redirect to particular page. – Ravichandran Jothi Jun 16 '11 at 14:09

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.

share|improve this answer
although this is true you can still use wordpress for 404 errors it has that built into it. – xLRDxREVENGEx Jun 16 '11 at 23:56
Sure, but didn't you want to bypass the WordPress 404.php? If you don't want to use the WordPress 404.php you need to use a server 404. Anything else will send the wrong headers to the browser. – Elpie Jun 17 '11 at 14:00
I can create a 404 page on WordPress and give it the same look as my site where as with a 404 from the server i have to grab the rendered code and add what i want to display. With the WordPress route its all dynamic. Also i am not the persona asking – xLRDxREVENGEx Jun 17 '11 at 17:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.