subdomain routing and link generation

Hi there, do you guys have an elegant solution for routing subdomain to the module / controller? Currently I have a virtual host that handle wildcard subdomain into one phalcon multi module project. A subdomain can route to specific module (e.g. routes to mobile module) or to a specific controller. My current solution is prepending the $GET['url'] with the subdomain and add a route for that. For example _url for is rewrited to /m/xxx/yyy and add a routing rule for /m/:controller/:action. But I think it would cause a duplicate content and I have to implement my own Phalcon\Mvc\Url and Tag::linkTo to generate a subdomain link. Any enlightment here please :)


Routing based on the hostname is still not supported by Phalcon, maybe you can implement this by adding routes conditionally based on the current host:


$di['router'] = function() {

    $router = new Phalcon\Mvc\Router(false);

    switch ($_SERVER['HTTP_HOST']) {
        case '':

            $router->add('/m/xxx/yyy', array(
                'controller' => 'xxx',
                'action' => 'yyy'

            $router->add('/xxx/yyy', array(
                'controller' => 'xxx',
                'action' => 'yyy'

    return $router; 


Now I thinking about domain-routing too. It may be very useful to divide service components from user components, for example uri which payments systems send success-payment-request to. I hope this feature will be supported by Phalcon directly and comfortable in future.

Any way you could implement this feature in 1.0.0 before it gets out of beta? I'll need this and switch is no solution for a SaaS ;)

HTTPHOST is populated from "Host:xxxxx " header coming with request. It makes domain routing not safe, just google "HTTPHOST spoofing".

I had this idea before but reconsidered and now I just use another index script file and virtual domain setup. Routes I keep in separate files, but bootstrap file is common for each application.

I just try to think if htacess could solve this issue but again it will mean rewriting every url used with the subdomain