Roel Jansen
Roel Jansen

Reputation: 376

Change DocumentRoot by URL path

How do I change the DocumentRoot according to the URL path using VirtualHost?

I want this:

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

Answers (1)

Eymard Neto
Eymard Neto

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

Related Questions