I would avoid the PHP request and go up one level. I haven't tried this, but maybe the .htaccess
file could help you, using something similar to this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^11.11.11.111/testsite$ [NC]
RewriteRule ^(.*)$ test.site.com/$1 [L,R=301]
You might have to play around with it, but I would imagine something along those lines should get you to where you want to be.