I was able to solve this without .htaccess.
In my wp-config.php I retrieved the sites in an array. You can get this from your database if you need to. I then preg-matched the url being entered and checked against the known sites. In my case all urls end with .com (I could always modify the preg if need be in the future for .net or w/e). I also sanitize the url just in case for security. I then basically tell wordpress when it goes to redirect to use the base domain (i.e the homepage of the accessed domain). The wordpress default is to go to the main site in your multisite install.
Here is my snippet:
preg_match('#^.*\.([A-Za-z]*.com)#', filter_var($_SERVER["HTTP_HOST"], FILTER_SANITIZE_URL), $match);
$attempted_domain = $match[1];
$domain = 'http://site1.com';
//wordpress handles the parent domain of multisite special; so DO NOT set NOBLOGREDIRECT for site1.com. For example site1.com/doesnotexist will not show a 404 page but the homepage instead which is incorrect so have to add this first if conditional
if($attempted_domain == $domain){
//otherwise check against our domain list and then redirect to that domain (site2.com/thisdoesnot exist will work correctly)
foreach($all_domains AS $known_domain){
if($attempted_domain == $known_domain){
$domain = 'http://'.$known_domain;
break;
}
}
define('NOBLOGREDIRECT', $domain);
}
1.) What's subtle to realize here is that DNS resolves your domain. So something like blah.awesome.crazy.foo.bar.site1.com will come to your site. In this case I am making sure that no matter how many sub domain levels exist I am checking against the base domain site1.com in my list of sites.
2.) NOBLOGREDIRECT will only be used if you attempt to go to a non-existent site. Missing pages/posts for example will still 404 as they normally would. See #4 for exception
3.) If for some reason the domain is not found use a default that we know exists. This could happen if for example we changed our DNS but didn't actually setup the site yet.
4.) There is a special case around internal wordpress functionality and NOBLOGREDIRECT when accessing the parent domain of the install. You'll notice that I don't ever set NOBLOGREDIRECT when the parent domain is the domain being accessed. Otherwise 404's are not shown for the parent, you get redirected to the homepage which is incorrect. Other domains on the install are not affected so we can use NOBLOGREDIRECT there.
.htaccess
file.