mod_vhost_alias was written for this task.
Uncomment (remove the #) from the following line in your http.conf file
- Code: Select all
LoadModule vhost_alias_module modules/mod_vhost_alias.so
and (if this line exists (Apache 1.3 only))
- Code: Select all
AddModule mod_vhost_alias.c
Then add the following to the end of your httpd.conf file
- Code: Select all
NameVirtualHost *:80
VirtualHost *:80>
ServerName localhost
DocumentRoot /srv/www/htdocs/
</VirtualHost>
<VirtualHost *:80>
ServerName 0.localhost
ServerAlias *.localhost
DocumentRoot /srv/www/htdocs/subdomains/
VirtualDocumentRoot /srv/www/htdocs/subdomains/%-2+
</VirtualHost>
When I access abc.localhost host is unreachable.
You will need to add the sub domains to your
hosts file, eg.
- Code: Select all
127.0.0.1 localhost
127.0.0.1 abc.localhost
127.0.0.1 def.localhost