You are asking for a custom coding solution and I am givinng you some options you can create yourself for your custom solution. You are not doing something standard so BPS is not going to magically read your mind or magically do something that is not designed to do. ;)
You would need to create .htaccess files for each add-on domain and NOT try and handle this from the primary domain. This is standard/basic site architecture and the best approach anyway - each website should have its own .htaccess file for all the right/correct industry/security standards, site architecture, site design, etc etc etc.