如何在apache2站点configuration文件中有一个dynamic的DocumentRoot?

我需要configuration我的evelynblac.com.conf文件,以便任何带有子域的请求都被映射到以子域名命名的目录(请参阅链接中的图像)。 我怎样才能做到这一点?

<VirtualHost *:80> ServerName evelynblac.com ServerAlias *.evelynblac.com ServerAdmin [email protected] DocumentRoot /var/www/*.evelynblac.com <Directory "/var/www/*.evelynblac.com"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

我的evelynblac.com.conf文件的屏幕截图

PS:我想要一个解决scheme,如果可能,不需要我修改.htaccess。

你可能想看看mod_vhost_alias

有了这个模块,你可以用variablesreplace虚拟主机,例如:

%0用​​FQDNreplace出现,其他variables是:

 0 the whole name 1 the first part 2 the second part -1 the last part -2 the penultimate part 2+ the second and all subsequent parts -2+ the penultimate and all preceding parts 1+ and -1+ the same as 0 

在你的例子中,你可能想要做一些事情:

 VirtualDocumentRoot /var/www/%0 

最后yoonix提到了很多方法,这只是其中之一。