I made a simple redirection plugin that works like this:
add_action('wp_head', 'myredir');
function myredir(){
if ( is_404() ) {
$Path=$_SERVER['REQUEST_URI'];
wp_redirect( 'http://old.example.com'.$Path );
exit();
}
}
The goal is redirect 404 errors to the old domain (I need to do a manual migration from an old website and it's going to take ages)
On Apache it works fine, on Nginx it doesn't work. What can I do to fix my plugin? The Redirection plugin works fine and it looks like is using wp_redirect, so there something wrong with my code
template_include
.wp_head
was always too late as Mark pointed out.