开发者

Using mod_rewrite with mod_vhost_alias

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜