Based on the question I think you don't understand the difference between Directory
and VirtualHost
.
<Directory>
and </Directory>
are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories.
<VirtualHost>
and </VirtualHost>
are used to enclose a group of directives that will apply only to a particular virtual host. Any directive that is allowed in a virtual host context may be used. When the server receives a request for a document on a particular virtual host, it uses the configuration directives enclosed in the <VirtualHost>
section.
The <Directory>
directive doesn't control "Directory type URLs". The DocumentRoot
and the Alias
directives controls where in the file system the content is found. Those directives can be used directly in the server config or inside a <VirtualHost>
.
For what you are trying to achieve you simply need two <VirtualHost>
s with different DocumentRoot
s, e.g.
Listen 80
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/examplecom"
ServerName example.com
</VirtualHost>
Now, you have both http://localhost/examplecom/
and http://example.com/
for the same website. If the sites aren't all under the same file system directory, you'd need to use Alias
es, e.g.
Listen 80
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
Alias "/examplecom" "/home/user/sites/example.com"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/home/user/sites/example.com"
ServerName example.com
</VirtualHost>