Yeah, its possible.
Add the following to your htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^((?!www\.).+)\.example.com
RewriteRule !index\.php http://%{HTTP_HOST}/user/index.php?name=%1 [L,R,NE]
The rule above will redirect foo.example.com to foo.example.com/user/index.php?name=foo