I have a site I am working on in which I need to have several domains redirecting to one main domain with www. preceding it, which I have already set up using htaccess

RewriteCond %{HTTP_HOST} !^www.maindomain.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.maindomain.com%{REQUEST_URI} [L,R=301]

So that anything not www.maindomain.com gets redirected to that domain instead permanently

However now I need to add something to state that if it matches www.maindomain2.com it should redirect to a sub folder of the hosting account and process a set of rules etc or if it matches anything else it redirects to www.maindomain.com and uses the site located in the root of the host and processes rules as usual etc

Usually on hosts such as godaddy you can easily set up multiple websites on one hosting account all using different domains and each site is contained in a sub folder of the main site

I need to do this on a host that doesnt have this feature built in and told me I need to do it manually myself in htaccess the root of the site

So if maindomain2.com is used it pulls site 2 from a sub folder and the domain and page urls in the address bar all look normal like they should with no reference to any sub folder or anything

and If maindomain.com (or several other domains related to that main site) is used it pulls site 1 from the root of the hosting account as usual

How can I achieve this and also have a different set of rules to apply to each within the htaccess file

Hope this is not written too confusingly

Thanks in advance