Apache 同一子域可能有多个虚拟文档根目录?

Apache 同一子域可能有多个虚拟文档根目录?,apache,apache2,virtualhost,Apache,Apache2,Virtualhost,我正在设置一个开发服务器,我想知道是否可以使用虚拟文档根设置多个虚拟主机作为同一子域的备用 为了澄清,假设我有这个虚拟主机,它基本上允许在ex1.somedomain.com下使用动态子域,文件夹名将成为子域的名称。这一切都很好 <VirtualHost [ip address here]:80> UseCanonicalName off VirtualDocumentRoot /home/firstuser/www/%1/public_html/ ServerAl

我正在设置一个开发服务器,我想知道是否可以使用虚拟文档根设置多个虚拟主机作为同一子域的备用

为了澄清,假设我有这个虚拟主机,它基本上允许在
ex1.somedomain.com
下使用动态子域,文件夹名将成为子域的名称。这一切都很好

<VirtualHost [ip address here]:80>
   UseCanonicalName off
   VirtualDocumentRoot /home/firstuser/www/%1/public_html/
   ServerAlias *.ex1.somedomain.com

   <Directory /home/firstuser/www/*/public_html/>
      AllowOverride all
   </Directory>

   AddHandler php5-fcgi .php
   Action php5-fcgi /php5-fcgi
   Alias /php5-fcgi /home/firstuser/www/php5-fcgi
   FastCgiExternalServer /home/firstuser/www/php5-fcgi -socket /tmp/php5-fpm-firstuser.sock -pass-header Authorization -idle-timeout 600
</VirtualHost>

配置这样的东西的正确方法是什么?

如果文件不存在,则没有内置的支持从一个虚拟主机跳到另一个虚拟主机,但是mod_rewrite手册中有一些方法向您展示了如何在将URI更改为文件系统映射之前查看文件系统

<VirtualHost [ip address here]:80>
   UseCanonicalName off
   VirtualDocumentRoot /home/seconduser/www/%1/public_html/
   ServerAlias *.ex1.somedomain.com

   <Directory /home/seconduser/www/*/public_html/>
      AllowOverride all
   </Directory>

   AddHandler php5-fcgi .php
   Action php5-fcgi /php5-fcgi
   Alias /php5-fcgi /home/seconduser/www/php5-fcgi
   FastCgiExternalServer /home/seconduser/www/php5-fcgi -socket /tmp/php5-fpm-seconduser.sock -pass-header Authorization -idle-timeout 600
</VirtualHost>
RewriteEngine on

#   first try to find it in dir1/...
#   ...and if found stop and be happy:
RewriteCond         "%{DOCUMENT_ROOT}/dir1/%{REQUEST_URI}"  -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/dir1/$1"  [L]

#   second try to find it in dir2/...
#   ...and if found stop and be happy:
RewriteCond         "%{DOCUMENT_ROOT}/dir2/%{REQUEST_URI}"  -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/dir2/$1"  [L]

#   else go on for other Alias or ScriptAlias directives,
#   etc.
RewriteRule   "^"  "-"  [PT]