Add a sudomain for each folder in my userdir path with Apache

983 Views Asked by At

I activated the userdir mod with apache2 and configure my domain to get the content of the www folder in my home. I create a Virtualhost for the main domain which works good. But now i would like to automatically add a subdomain for each folder in my /home/user/www/

Here is the virtualhost i code, but it redirect all the subdomains to the /home/user/www/

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mysite.com
ServerAlias *.mysite.com

DocumentRoot /home/user/www/

UseCanonicalName Off
VirtualDocumentRoot /home/user/www/%1

<Directory /home/user/www/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

ErrorLog /var/log/apache2/error.mysite.log
LogLevel warn

CustomLog /var/log/apache2.mysite.log combined
</VirtualHost>`
1

There are 1 best solutions below

4
On

Try changing:

VirtualDocumentRoot /home/user/www/%1

to:

VirtualDocumentRoot /home/user/www/%0

You can read more about this feature at mod_vhost_alias.