Redirect to a page if ancestors is empty

The simple answer is wp_redirect($url);, but it’s a tricky beast to use as you can only use it before any page output. So basically, what you have would need to be right at the top of your page

This example is making the assumption that you are using this in single.php? –

$post_id = $post->ID; 
$ancestors = get_post_ancestors($post_id);

if(empty($ancestors)) : // Not sure how $ancestors is returned, this assumes it's an array
    wp_redirect($url);
    exit;
endif;

See the Codex of wp_redirect() for more information.