Kohana's routing system only allows you to parse the URI, so you can't do it in a clean way. But, you can do something like this to have your desired behaviour:
$controller = preg_match('/^([\w]+)\.example\.com$/', $_SERVER['HTTP_HOST'], $match)
? $match[1]
: 'main';
Route::set('default', '(<action>(/page<page>)(/<id>))')
->defaults(array(
'directory' => 'index',
'controller' => $controller,
'action' => 'index',
));
However, this routing won't work in console (php index.php --uri=<uri>
), because HTTP_HOST
isn't defined.