I was wondering if it's possible to use the vhost_alias module in conjunction with a rewrite rule. So in my VirtualHost I have this:
VirtualDocumentRoot /var/www/%2+/%1
For example, sub.mydomain.com will point to /var/www/mydomain.com/sub/
But I want to check if the folder exists to avoid getting a 404 error if I try to reach a bogus subdomain.
So I tried to do this
RewriteCond /var/www/%2+/%1 !-d
RewriteRule ^.*$ www.mydomain.com
But it doesn't work. Any ideas?
Found another way to do what I wanted:
RewriteRule ^(.*)$ %{HTTP_HOST}/$1
RewriteRule ^(.*)\.([^/.]*)\.([^/.]*)\/(.*) /home/vhosts/$2.$3/$1$4 [E=VIRTUAL_ROOT:/home/vhosts/$2.$3/$1]
RewriteCond %{ENV:VIRTUAL_ROOT} !-d
RewriteRule .* http://www.mydomain.com [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.