views:

161

answers:

1

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?

A: 

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]
Alexandre