Skip navigation

Tag Archives: subdomain

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\

<VirtualHost *:80>
ServerName company.lc
DocumentRoot D:/htdocs/web/public/company/app/webroot
ServerAlias *.company.lc
</VirtualHost>

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.