Ideally, you should be making each of these subdomains into a separate vhost and point each vhost to its own directory. Some hosting companies even allow you to assign subdomains to separate directories.
But if for some reason, they all need to point to the same document root, try adding these rules to the htaccess file in the document root:
RewriteEngine On
# for company1
RewriteCond %{HTTP_HOST} company1.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/directory1
RewriteRule ^(.*)$ /directory1/$1 [L]
# for company1.test
RewriteCond %{HTTP_HOST} company1.test.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/directory2
RewriteRule ^(.*)$ /directory2/$1 [L]
# for company1.cert
RewriteCond %{HTTP_HOST} company1.cert.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/directory3
RewriteRule ^(.*)$ /directory3/$1 [L]