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

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.