First, make sure that all subdomains are pointing to the same host (wildcard). This is usually done in the configuration file of the Apache host.
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
...
Then you should get the desired redirect to work with the following configuration:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/index.php/%1/$1 [L,NC,QSA]
Reference:
Redirect wildcard subdomains to subdirectory, without changing URL in address bar
Update 1:
Here is the update for you multi-wild-card scenario. Note that I changed the last line - I explicitly call the index.php of the base url, like this the output of $_SERVER['PHP_SELF'] should be /index.php/portal/index.html (or php according to your Apache configuration).
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.(.*)$
RewriteRule ^(.*)/?$ http://%2.%3/index.php/%1/$1 [L,NC,QSA]