Well, one way to do it is to check your server port...
if ( $_SERVER['SERVER_PORT'] == 80 )
{
header ( "Location: [url]https://www.domain.com[/url]" );
exit;
}
Now, of course, you'd have to make sure that you're using the right port for your main server, but chances are that's the right one...it's kind of the standard. :p