I have two domains pointing to a site hosted by apache2 (a.com and b.com for example). The primary domain is a.com and the website can be accessed from this domain.
However, the page a.com/test/ should redirect to b.com (not b.com/test/) to display the content from the server and this content should also be displayed if b.com is accessed directly.
I thought that reverse proxies might be the way to go but haven't had any luck, I was wondering if this is possible to do within my .htaccess file (both domains are pointing to the server).
You shouldn't need a reverse proxy. As long as both a.com and b.com's DNS point to the same apache server, you can set this up by just using vhosts and a redirect.
For the b.com vhost, just make it's DocumentRoot
the test folder (full path). If that's not possible the you can also do this via htaccess.
For the redirect, add this to the htaccess file in a.com's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} a\.com$ [NC]
RewriteRule ^test/(.*)$ http://b.com/$1 [L,R=301]
and for b.com if you can't set the DocumentRoot
in the vhost
RewriteCond %{HTTP_HOST} b\.com$ [NC]
RewriteCond $1 !^test/
RewriteRule ^(.*)$ /test/$1 [L]