[Solved] Symfony sub domain routing


This solution will intercept the REQUEST_URI and add the subdomain as a root folder if not already used.

Meaning app.example.com and app.example.com/app will both access the same page.

if(substr($_SERVER['HTTP_HOST'], 0, strlen('app.')) === 'app.'
    && substr($_SERVER['REQUEST_URI'], 0, strlen('/app')) !== '/app')
{
    $_SERVER['REQUEST_URI'] = '/app'.$_SERVER['REQUEST_URI'];
}

The benefit of this is being able to put all your controllers in folders. If you had a multiple profile controllers, they could both be accessed from /profile but under different sub domains.

solved Symfony sub domain routing