Hide custom post type slug url from search engine [closed]

Instead of showing a 401, why not just add the URL to a robots.txt and the search engine will ignore it from indexing.

You could also manually add to the headers a meta robots to noindex the page.

You could run this via .htaccess to redirect a page to somewhere else (or show 401), but that would show for both users and search engines.