0

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/
tereško
  • 58,060
  • 25
  • 98
  • 150
iDev247
  • 1,761
  • 3
  • 16
  • 36
  • 1
    Off-topic, but will the store-websites show the same *content*? If they do, you'll probably get a duplicate content penalty when Google is indexing those websites – thaJeztah Apr 17 '13 at 19:09
  • 1
    Can you handle it within an htaccess file? – Dave Apr 17 '13 at 19:13
  • Thanks theJeztah for note. It's something we've considered. The main domain name will have completely different content from the stores. The stores however will have similar content. We were thinking of having a main store (all products) and a bunch of secondary stores (some of the products). The secondary stores would point to the main store with a canonical meta to try to reduce duplicate content. – iDev247 Apr 17 '13 at 19:15
  • Dave you're right. I can do some htaccess trickery (using Nginx so would use Nginx alternative). Hacking stuff up together right now. I'll temporary add a condition in my routes.php (as per oikku's suggestion). Once I'm done hacking I'll try something with the Nginx rules. – iDev247 Apr 17 '13 at 19:18

1 Answers1

1

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.

oikku
  • 542
  • 2
  • 7
  • Thanks! I'll try this for now. I wonder it's a correct practice to add conditions in the routes.php file or if it should somehow be in a controller or boostrap.php or core.php. – iDev247 Apr 17 '13 at 19:20