php preg_match。 将子域更改为子文件夹虚拟

sorry, I'm not good at php, this might be a very obvious mistake. I'm trying to this:

if(preg_match('#([a-z0-9-]+?)\.domain\.com#i', $servername, $blogname)){


    }   
        if ( check_suspend ( $blogname[0] ) ) {
        if(isset($_GET['id']) ){
            $res=mysql_query("select id,username from `feeds` where `id`=(select fid from `news_tmp` where `id`=$_GET[id]) limit 1");
            if(mysql_num_rows($res)>0){
                list($id,$username)=mysql_fetch_array($res);
                if($blogname[1]!=$username){
                    Header( "HTTP/1.1 301 Moved Permanently" );
                    Header( "Location: http://$username.domain.com/post/$_GET[id]" ); 
                    exit;               
                }
            }
        }

I have link like : http://test313.domain.com/post/123456/

But I want to have url like http://domain.com/test313/post/123456/

I change

Header( "Location: http://$username.domain.com/post/$_GET[id]" ); 

to

Header( "Location: http://domain.com/$username/post/$_GET[id]" ); 

But page won't load. I think this is for line 1 > "preg_match".

Note : I enabled wildcard on my host. (Virtual subdomains)

Thanks in advance.