Using Apache, I have set up the VirtualDocumentRoot and it works this way:
<VirtualHost *:80>
UseCanonicalName Off
ServerName app.example.com
ServerAlias *.example.com
VirtualDocumentRoot "/home/domains/example.com/%1"
<Directory "/home/domains/example.com/*">
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
If I put the URL of http://mail.example.com
, the DocRoot becomes /home/domains/example.com/mail
, if it is http://www.example.com
, the DocRoot becomes /home/domains/example.com/www
, and so on.
Now I would like to check for the folder if it exists, like when the user requests a domain like http://myusername.example.com
, the DocRoot checks /home/domains/example.com/myusername
and it doesn't exist, so it should refer to /home/domains/example.com/404
. Is this possible?
I have referred the following questions but no good: