Using .htaccess pointing domain to specific directory

If a server hosting 2 domains, we can use this .htaccess (on the root) to point the 2 different domains to 2 Directories on the same server:

RewriteEngine On
RewriteBase /

# pointing for the domain domain1.com to folder1
ReWriteCond %{HTTP_HOST} domain1.com
ReWriteCond %{REQUEST_URI} !folder1/
ReWriteRule ^(.*)$ folder1/$1 [L]

# pointing for the domain domain2.com to folder2
ReWriteCond %{HTTP_HOST} domain2.com
ReWriteCond %{REQUEST_URI} !folder2/
ReWriteRule ^(.*)$ folder2/$1 [L]