url mapping/routing/dispatching in CakePHP

I ran into a limitation in cakePHP’s dispatcher - it is not domain sensitive. You can’t point /news/ or /projects/ or whatever to different controllers for different domains. Sure - you can check the domain in “news controller” or “projects controller” or whatever, but keeping them separate is what I’m after. Basically.. I have one cms that powers a bunch of related sites. These sites all have their own quirks, but a large part of the functionality is common.

This problem doesn’t only affect cakePHP - it seems to affect all the mayor web frameworks. I know Django’s url dispatcher and Routes (a python implementation of Rails’ routes) doesn’t allow you to treat different domains differently either. As far as I know (and I speak under correction here) cherrypy (and therefore turbogears) also doesn’t really allow you to send things to different places based off the domain name.

I suppose I have a bit of a “fringe case”, but I did have this problem before as well. The solution there was different, though. I knew the admin interface would only be on one domain and for all the others I didn’t know the urls beforehand anyway (and therefore had to calculate it off my data), so I just sent everything for the frontend to one controller action and then worked from there.

This time, I’ll just hack the dispatcher to include a route configuration file per domain and I’ll put all the controllers and views in domain-specific folders. (something like that)

I wonder if other people had the same problem and how they tackled it..

Leave a Response

(will not be published)
(optional)

Remember Me