mod_rewrite for wildcard subdomains
===

I need help in writing a mod_rewrite to allocate users their own personal subdomains. 

I want to convert sub.domain.com to sub.domain.com/profile?user=sub 

but if user opens any page the 'user' variable should also be passed i.e. 

sub.domain.com/page  to  sub.domain.com/page?user=sub

It should be masked i.e. no redirect 

