What is the best way to handle subdomains
I would like to have multiple subdomains pointed to my project. For instance, site1.web.com, site2.web.com, site3.web.com. What is the best way to accomplish this? Potentially, there will be 10,000 subdomains pointing to this project.
Asked by Roborino, on 24/11/09
1 Answer
Setup a default virtualhost on apache that will serve your sites webroot if no other hosts are matched, or setup a system whereby you can easily add new vhost definitions pointing to that existing webroot path.
I am assuming you also want to differentiate content based on the subdomain that is accessed, to provide a multi-tenancy application.
You can use URI inspection to determine what site has been accessed. This information is kept in the HTTP_HOST variable set on the request sent by the client.
You can see an example of this by throwing this into a controller or view somewhere:
echo env('HTTP_HOST');
Use this as the key for the subdomain information you want to load:
$this->SomeModel->find('all', array(
'conditions' => array(
'domain' => env('HTTP_HOST'))));
Answered by predominanton 24/11/09
Rating
4
Viewed
3235 times
Last Activity
on 24/11/09






