在apache虚拟主机文件中的通配符替代

我正在尝试设置一个将xyz.mycompany.com路由到/ var / www / html / development / xyz / public的apache虚拟主机文件

这是我的硬编码版本。 有没有办法用variables交换“xyz”?

<VirtualHost *:80> ServerName xyz.mycompany.com ServerAlias xyz.mycompany.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html/development/xyz/public ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/development/xyz> AllowOverride All Options -Indexes +FollowSymLinks +MultiViews Order allow,deny Allow from all </Directory> </VirtualHost> 

请阅读这个: Apache2dynamic文档根据URL

你可以这样做:

 <VirtualHost *:80> ServerName xyz.mycompany.com ServerAlias *.mycompany.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html/development/%1/public ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/development> AllowOverride All Options -Indexes +FollowSymLinks +MultiViews Order allow,deny Allow from all </Directory> </VirtualHost> 

关于<Directory>部分,我认为你可以为整个开发目录设置你的选项。

mod_macro可以在configuration文件中进行variablesreplace。 然而,你的主题说“通配符replace”,当然Apacheconfiguration文件可以处理* 。 在你的情况下, ServerAlias *.mycompany.com将发送mycompany.com以外任何子主机的任何主机头到您的/var/www/html/development/xyz目录中。