Is it possible to redirect all 404 subdomain result to the root domain in apache2? Im using a wildcard subdomain entry in my DNS provider, and apache is set to fetch the site in the folder with the same name as the subdomain. But I would also like it to be able to redirect its self to the root domain if there is no folder.
NameVirtualHost *:80
# Root domain
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public
</VirtualHost>
# Wildcard subdomains
<VirtualHost *:80>
ServerAlias *.example.com
VirtualDocumentRoot /var/www/%0/public
# Redirect to root if `$0` folder doesn't exist
</VirtualHost>