1

I'm trying to set up a single apache virtualhost file that will route xyz.mycompany.com to /var/www/html/development/xyz/public

Here is my hard-coded version. Is there a way to swap "xyz" with a variable?

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

2 Answers 2

1

Please read this one as well: Apache2 dynamic documentroot depending on URL

You can do this:

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

Regarding the <Directory> part, I think you can set your options for the entire development directory.

2
  • Update: "DocumentRoot" needs to be "VirtualDocumentRoot", and you have to run a2enmod vhost_alias to install the VirtualDocumentRoot command beforehand. Finally, run service apache2 reload
    – Anthony
    Dec 31, 2014 at 18:19
  • You are welcome.
    – Iulian
    Jan 1, 2015 at 18:18
1

mod_macro can do variable substitution in config files. However your subject says "wildcard substitution" and certainly Apache config files can handle *. In your case ServerAlias *.mycompany.com would send any host headers for any subdomain off of mycompany.com into your /var/www/html/development/xyz directory.

1
  • Thanks Wesley. I think lulian's answer more closely matches what I'm looking for. I'm trying to match the subdomain to the directory.
    – Anthony
    Dec 31, 2014 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .