Make sure you do not have: get_header(); or any WordPress feature that potentially creates content like the header and footer in your template. Otherwise, the redirect will not work.
Some developers try to clear the page using ob_start(); but if you have content on your page, even if you use ob_start(); redirection will not work.
and then just try this code:
wp_redirect(get_permalink($post->ID)); exit;
source share