How to 301 redirect all non-existing sub sites to main site?

Hi,
Multisite question: I need to 301 redirect all non existing sub sites to the main domain (domain.com). Everything I've tried in .htaccess breaks the site. I know how to use no blog redirect in wp-config but that is a 404 error I'm assuming. I need a 301 if possible?

Thanks!