I am doing this under windows 7+Apache on my local machine. So it’s a local environment. Production setup might change slightly.
In apache httpd-vhosts.conf, which can be found in Apache2.2\conf\extra\
ServerName company.lc
DocumentRoot D:/htdocs/web/public/company/app/webroot
ServerAlias *.company.lc
And in windows hosts file which can be found windows\system32\drivers\etc\ in windows 7
127.0.0.1 test.company.lc
127.0.0.1 company.lc
since windows hosts doesnt allow dynamic subdomain. You have to type out each subdomain you want accessible through your browser locally. Not a big deal.
Restart apache. If it doesn’t work. Flush your local dns by typing ipconfig /flushdns in cmd.exe.
Now you should be able to access test.company.lc correctly.
I have a function in my app_controller.php for grabbing the subdomain and do some comparison and checking. It’s very simple though flawed in some way.
function getSubdomain() {
$domain = parse_url($_SERVER['HTTP_HOST']);
$domain = explode('.',$domain['path']);
if(count($domain)==3 and !empty($domain[0])) {
return $domain[0];
}
return '';
}
And there you have it.