Something like that:
RewriteEngine On RewriteCond %{http_host} ^domain.com [nc] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC] RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] RewriteRule ^users/([a-z0-9\-_\.]+)/?(.*)$ http://$1.domain.com/$2 [QSA,NC,R,L]
Do you have any other rules besides those listed in the question? if so, put them in front of another.
eg:
http://www.domain.com/users/abc?q=test => http://abc.domain.com/?q=test http://www.domain.com/users/abc/sub1/sub2 => http://abc.domain.com/sub1/sub2 http://www.domain.com/users/abc/sub1/?q=test => http://abc.domain.com/sub1/?q=test
source share