Reputation: 376
How do I change the DocumentRoot according to the URL path using VirtualHost?
I want this:
example.com
to serve /var/www
example.com/2
to serve /var/www2
I'm using Alias, which serves the correct directory, but doesn't change the 'DOCUMENT_ROOT' server variable.
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName example.com
Alias /2 "/var/www2"
</VirtualHost>
Upvotes: 1
Views: 1748
Reputation: 11
Your document root, the top-level directory that Apache looks at to find content to serve, will be set to individual directories under the /var/www directory. You will create a directory in this path for your virtual hosts. Like this:
sudo mkdir -p /var/www/www1
sudo mkdir -p /var/www/www2
Then in your virtual host config you will do the follow:
<VirtualHost *:80>
DocumentRoot "/var/www/www1"
ServerName example.com
Alias /2 "/var/www/www2"
</VirtualHost>
Upvotes: 1