Вопрос

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

  • Domain name x.com (our main app domain) to link to: controller: pages | action: home
  • Domain name y.com or z.com (stores created via our main app domain) to link to: controller: stores | action: index

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:

  • In AppController's beforeFilter I perform some database checks. It checks to make sure that the store does exist (via Store model). If the store/domain doesn't exist it redirects to our main domain name.
  • I want to keep the URL clean. I don't want to redirect to pages based on the domain name. Redirecting would mean the homepages would look like like http://x.com/pages/home/ simply like http://x.com/
Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top