Have WordPress (which creates the web server responses) respond with a redirect (via a call to wp_redirect()
). Put as the first thing in header.php
global $post;
if( needs_replacement( $post ) ) {
$from_url = create_url( $post );
wp_redirect( $from_url );
exit(0);
}
require_once( get_template_directory() . '/page.php' );
?>
(Note that you have to this first thing; otherwise, attempts to redirect will get ignored or more likely cause errors.)