If the different sites do not need to access each others content, I think, that it would be the best solution to keep the websites completely separated. So each website has it’s own Kirby installation.
But I don’t know what your specific use case is.
But in this case you would only have to change the RewriteBase line in the .htaccess file from RewriteBase / to RewriteBase /site1name.
I’m using this for developing my websites on localhost.
Otherwise you must create a custom site.php file in your Kirby installation folder as mentioned in the Custom folder setup.
But instead of switching folders my domains, you should be able to get the requested URI by server::get('REQUEST_URI'), trim this string to the first / by using string manipulation and use this as switch for the different sites.
It should be possible, but I have not tested this.