One solution is to use Parameterizing Hostnames (at the bottom). When you then create an url, it will contain the full host info. A problem is that the config is a little bloated and when you change your domain, you must change all url rules. You may do something like this for flexibility:
// Use different hosts for debugging and production + easy to modify later
$host = YII_DEBUG ? 'http://localhost' : 'http://example.com';
'components' => array(
...
'urlManager' => array(
...
'rules' => array(
"{$host}" => 'site/index',
"{$host}/contact" => 'site/contact',
...
),
),
...
),
You can define the params array in config. If you want to automate this, you may create a special UrlManager component for the console application that will auto-prefix a created url with the correct host.