Dynamic subdomain pointing to html folder

ConnorM12 asked:

I have a PHP script that takes the subdomain i.e blah.example.com and runs a query based on that.

The problem I have is that I can’t get my new server to route any subdomain that someone may type to the HTML folder to run that command.

I can’t manually add the subdomains since I wont know them so I want to be able to set it so that the user can enter https://anything.example.com and the script runs.

I’m using Apache 2.4 on CENTOS 7

My answer:

Within your <VirtualHost> you can set a ServerAlias that uses a wildcard hostname. For example:

<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com

Note that it must be a ServerAlias. The ServerName must be a fully qualified domain name and cannot have wildcards. It is the primary name for that virtual host.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.