在apache中获取URL的一部分

I have set wildcard vhosts in my apache like

<VirtualHost *>
  ServerName wildcard.test.com
   ServerAlias *.test.com

   DocumentRoot = /var/www/test
   # other configuration for this app here

</VirtualHost>

I have created some sub domains like front.test.com and admin.test.com. I just want to know if there is a way in APACHE to get the first part of the URL like in above cases, I want test and admin and send it to my server side language some how. I repeat that I am looking for a possible way in apache, as people always say

you can not always trust what $_SERVER returns I will go for server side after confirming that there is not any way doing it on apache Thanks

$_SERVER can be trusted. Everything in $_SERVER is 'true'. But that doesn't say you should trust it. It holds the Query_String, HTTP_HOST, ... and these come from a request the user made. It is the user that shouldn't be trusted.

If a person types in foo.test.com then 'foo.test.com' will be the value of $_SERVER['HTTP_HOST'];

So I don't really see what the problem is.