Resolving Wildcard DNS subdomains in Virtual
hosts in Apache webserver (WildCard Virtual Hosts)
The company for which I'm employed as a free lancer, has a
requirement to start-up a new website on a different Debian Linux
powered server.
In connection to that they needed to change the DNS records to
point to the new IP address of the server.
That was a piece of cake, all I had to do was,
edit the domain
name zone file and change the A (Active) record to point to another
IP address
The trouble was that in this concrete scenario the website domain
has previously had
Wildcard DNS
record enabled earlier on.
So domains like
bla.exampledomain.com, asdf.exampledomain.com
you-name-it.exampledomain.com was configured to resolve to the
IP address determined for the
exampledomain.com
Therefore it was necessery that Apache is configured to serve any
incoming request on any
*.exampledomain.com subdomain
accessed.
Fortunately this is really easily achievable and is described in
Apache
Named-based Virtualhost documentation
In short all you need to make your Apache start serving all
incoming requests to any subdomain is to edit your Virtualhost on
Debian for the default subdomain that would mean to edit:
edit /etc/apache2/sites-available/000-default
debian-server:~# vim
/etc/apache2/sites-available/000-default
# Therein you will have to add the following line
ServerAlias domainexample.com
*.domainexample.com
That's is all necessery, now restart the webserver as usual for the
new configuration to take affect.
debian-server:~# /etc/init.d/apache2
restart
Congrats, now all your subdomians for the domainexample.com like
for instance:
http://bla.domainexample.com or
http://somerandom-word.domainexample.com should open
http://domainexample.com .