Yesterday @christopher commented "how to configure subdomain in Apache" under the post "Install Apache and Create Virtual Directory in Window 7". To be honest, I'm now currently developing CF development on Window 7 that's why I know how to configure subdomain in Window 7, not on Linux or other OS. To configure in subdomain, we need to do in 2 parts.

  • To configure in hosts file of window
  • To configure in Apache httpd.conf

1) To configure in hosts file of window

First of all, we need to find hosts under the following location. C:\Windows\System32\drivers\etc (it's for window7, if you're using another window version, search under System32 folder.) Then, open hosts with notepad and you will see the following codings.

Here is the below part of hosts file.

view plain print about
1# localhost name resolution is handled within DNS itself.
2#127.0.0.1     localhost

So, we need to do some configuration into this file as follow.

  • remove comment "#" from 127.0.0.1
  • set the name of your subdomain and IP address

After that, the final coding will be as follow:

view plain print about
1<!--- I've set my subdomain name as "pos.localhost" --->
2
3# localhost name resolution is handled within DNS itself.
4127.0.0.1     localhost
5127.0.0.1      pos.localhost

It's finished first part of hosts file. The, let's continue for Apache.

  • Open httpd.conf file
  • Add the following codings

The following coding, you need to change the DocumentRoot as the directory where your project is in.

view plain print about
1# Use name-based virtual hosting.
2NameVirtualHost *:80
3
4You need to change
5
6<VirtualHost *:80>
7DocumentRoot E:\Project\POS
8ServerName pos.localhost
9</VirtualHost>
10
11<VirtualHost *:80>
12DocumentRoot E:\Server\htdocs
13ServerName localhost
14</VirtualHost>

Configure above coding as you need and paste it into httpd.conf file. Then, restart your Apache and type your subdomain URL into the browser and run it. You will get it 100% WORKS..!!!!!

***ATTENTION : we need to put subdomain configuration first in httpd.conf file, then put the configuration of maindomain.***