WordPress restrict access to rest only

I’m not sure if this is a proper solution. But finally, I’ve decided to modify the blog theme.

<?php
function Redirect($url, $permanent = false)
{
    header('Location: ' . $url, true, $permanent ? 301 : 302);

    exit();
}

Redirect('/blog/admin/wp-admin/', false);
?>

So the WordPress website is not accessible at all, but I’m still able to access wp-admin and wp-json.