The .htaccess file modifies apache settings based on the file system location, where you want to change settings based on the virtual host context.
So instead of setting up authentication in the .htaccess file, modify the Apache configuration file and add authentication settings to the correct virtual host entry:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
<Directory /some/path/public_html>
AuthUserFile /some/path/public_html/.htpasswd
AuthGroupFile /dev/null
AuthName "authenticated Users Only"
AuthType Basic
Require valid-user
</Directory>
</VirtualHost>
Instead of using a <Directory /some/path/public_html> directive this could also be good use-case for <Location /public_html> directive within the virtual host context.
On a side note the strong recommendation from the Apache project with regards to .htaccess files:
You should avoid using .htaccess files completely if you have access
to httpd main server config file. Using .htaccess files slows down
your Apache http server. Any directive that you can include in a
.htaccess file is better set in a Directory block, as it will have the
same effect with better performance.