htaccess rewrite using wildcard and multiple subdomains
===

I want to implement a TEST, CERT and PROD webpages on one single webhosting using a single domain. 
The websites is using wildcards for the first subdomain.


I have the following code (thanks to a previous post):

    # for TEST
    RewriteCond %{HTTP_HOST} (.*).test.domain.com
    RewriteCond %{REQUEST_URI} !^/directory3
    RewriteRule ^(.*)$ /directory3/$1 [L]
    
    # for CERT
    RewriteCond %{HTTP_HOST} (.*).cert.domain.com
    RewriteCond %{REQUEST_URI} !^/directory2
    RewriteRule ^(.*)$ /directory2/$1 [L]
    
    # for PROD
    RewriteCond %{HTTP_HOST} (.*).domain.com
    RewriteCond %{REQUEST_URI} !^/directory1
    RewriteRule ^(.*)$ /directory1/$1 [L]


This has 3 problems:<br>
**1)** The URL is changed in the browser adress bar so the user can see the new URL.
I would like the user the see the original types URL<br>
Showing:

    http:\\subdomain1.cert.com\directory2
instead of:

    http:\\subdomain1.cert.com

**2)** The TEST and CERT Rewrite is having a `Internal Server Error`. <br>
It works fine when I replace the wildcard for an fixed subdomain

**3)** The PROD RweriteCond is always valid (also for the CERT and TEST sub. This means that it is always forwarded to directory1
<br>
<br>

I hope somebody can help me with this. The rewrites are kind of magic for me.

Thanks
