Wildcard subdomain with htaccess

In previous post, we saw how to redirect by string and pass the query string as REQUEST to another file.

It also possible to pass the sub-domain as REQUEST as bellow.

# To prevent the looping
RewriteCond %{ENV:REDIRECT_STATUS} !200

RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.localnuclo\.com$ [NC]

RewriteRule ^(.*) /index.php?folder=%2&query=$1 [L,QSA,NC]

Example :
if the URL is http://subname.domain.com/login

the output will be
http://subname.domain.com/index.php?folder=submane&query=login