phpcakephpcakephp-2.1cakephp-routing

CakePHP dynamic homepage based on domain name


I'm looking to change the homepage of my app based on the domain name.

To set the homepage this route is defined:

Router::connect('/', array('controller' => 'pages', 'action' => 'home'));

Question: How do I make this dynamic and add conditions so that a different controller/action is loaded based on the domain name?

Notes:


Solution

  • One way that comes to my mind is to parse domain before loading Cake and load different route configurations(separate files for example) for different domains. That way you can load different configuration for every domain and so the same path can be assosiated with different controller for different domain.