I have a wildcard ssl setup on Apache for a domain so that I can create any type of sub-domain on the fly.
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerName www.domain.com
ServerAlias domain.com *.domain.com
....
</VirtualHost>
This works great as I add sub-domains often and I don't need any other special handling.
Of course the issue is that now anyone can go to a default page with any random sub-domain. i.e. random.domain.com
What are my options here for limiting access to only the sub-domains that are currently setup? Would a rule in htaccess be viable? Something like if it's not one of these current sub-domains:
RewriteCond %{HTTP_HOST} !^sub\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^sub2\.domain\.com [NC]