1

I need to configure my evelynblac.com.conf file so that any request with a subdomain gets mapped to the directory named after the subdomain (please see image in link). How can I do this?

<VirtualHost *:80>
        ServerName evelynblac.com
        ServerAlias *.evelynblac.com
        ServerAdmin support@evelynblac.com
        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>

Screenshot of my evelynblac.com.conf file

PS: I'd like a solution that does not require me to modify .htaccess if possible.

Evelyn
  • 11
  • 3
  • 1
    Have you looked at the [official documentation](https://httpd.apache.org/docs/2.2/vhosts/mass.html)? –  Jan 08 '16 at 19:10
  • Thanks for that -- I had a look but it's a bit beyond my skill level. I just need someone to break it down for me here. – Evelyn Jan 08 '16 at 19:14
  • 1
    There are many methods and that page summarizes the easiest ways. Really, you should read through those and make the decision on which best suits you. My hunch is the one named _Simple dynamic virtual hosts_ would be plenty for your needs. –  Jan 08 '16 at 19:19
  • @yoonix ok thanks for the lead. I'll look into it. – Evelyn Jan 08 '16 at 19:21

1 Answers1

1

You might want to have a look at mod_vhost_alias

With this module you can replace virtual hosts with variables, eg:

%0 replace the occurance with the FQDN, other variables are:

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

In your example you might want to do something like:

VirtualDocumentRoot /var/www/%0

At the end there are many methods as yoonix mentioned, this is just one of them.

Thomas
  • 411
  • 3
  • 4