我做的!
首先,我们需要启用两个 mod:mod_vhost_alias 和 mod_rewrite
sudo a2enmod vhost_alias
sudo a2enmod rewrite
1] 在 /etc/apache2/sites-available 中创建一个新的虚拟主机,我将它命名为 zzz-dev
<VirtualHost *:80>
#All requests ending with .dev will use this virtualhost
ServerName dev
ServerAlias *.dev
# Get server name of header Host:
UseCanonicalName Off
# Interpret the request url to find the right project folder. Ex: For customer1.project1.dev, %1 is the first part (here: customer1), %2 the second part (here: project1), so the folder for this url is /home/victor/takative/projets/customer1/project1/public
VirtualDocumentRoot /home/user/mainprojectdirectory/%1/%2/public
# Fix for missing $SERVER['DOCUMENT_ROOT'] while using VirtualDocumentRoot, the setDocumentRoot.php file will be added autmatically to set the variable
php_admin_value auto_prepend_file /home/lib/utils/setDocumentRoot.php
RewriteEngine On
RewriteOptions Inherit
<DirectoryMatch "/home/user/mainprojectdirectory/.*">
IndexOptions +FancyIndexing NameWidth=*
Options Includes FollowSymLinks Indexes
AllowOverride All
Order allow,deny
Allow from all
</DirectoryMatch>
</VirtualHost>
以下是 setDocumentroot.php 的内容:
<?php
$_SERVER['DOCUMENT_ROOT'] = str_replace($_SERVER['SCRIPT_NAME'], '',$_SERVER['SCRIPT_FILENAME']);
?>
2]启用新的虚拟主机:
sudo a2ensite zzz-dev
3]重新加载apache:
sudo service apache2 reload
4]现在,要创建一个项目,您只需按照上面的文件夹层次结构并使用以下行编辑 /etc/hosts 文件:
127.0.0.1 customer1.project1.dev
希望能帮助到你。如果有人有改进此配置的建议,我很乐意。谢谢