Create a block of the following 3 lines for each directory you want to do this for. Do this after the RewriteEngine on
directive. In this example, www.example.com is the domain that you want to be used for the directory.
RewriteCond %{REQUEST_URI} ^/directory1(.*)
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule .* http://www.example.com%1 [L,R]
Once you've tested it, change [L,R]
to [L,R=301]
to denote a permanent redirect for better SEO friendliness. I don't have it to start because it complicates testing since it causes browsers to cache the redirect.
For the above to work, you'll need to make sure the server is configured to listen for the other domain and when that domain is accessed, use the full path to the subfolder (directory1 in this case) as the document root for the domain.
If you don't know how to do that and don't mind it having the subdirectory in the URL, then configure the other domain to use the same document root as the main domain and then use the following rules:
RewriteCond %{REQUEST_URI} ^/directory1.*
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule .* http://www.example.com%{REQUEST_URI} [L,R]