How to redirect correctly a root domain to a subdomain in a subfolder?

This is the adopted answer, thanks to @anubhava:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} !subdomain.example.com [NC]
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L,QSA]
</IfModule>

Sourse: https://stackoverflow.com/a/19323457/1354580