27

I'm currently using name-based virtual host configuration, to server about 5 different websites from the same IP address, just like in the apache documentation:

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Is it possbile to have something like:

<VirtualHost *:80>
ServerName www.domain.tld/folderpath
DocumentRoot /www/software
</VirtualHost>

The webpages in this folder are using a different software stack, and I'd like to keep it nicely separate. I tried the method above but it didn't work.

me_pongo
  • 273
  • 1
  • 3
  • 4

3 Answers3

45

It's not possible the way you show - a VirtualHost is always just a host. But you could use an Alias.

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain

Alias /folderpath /www/software

</VirtualHost>
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 7
    Sweet. For reasons too ridiculous to explain, this is exactly what I needed. – eimajenthat Aug 13 '13 at 19:26
  • Any idea how to undo this? I did the Alias, it worked beautifully. Now I no longer need it so I've removed it, but the server keeps trying to remember it. All explained here: http://stackoverflow.com/questions/38042221/virtualhost-keeps-redirecting-to-deleted-alias-information – thanks_in_advance Jun 27 '16 at 00:45
  • @eimajenthat how will the website be accessed then? www.domain.tld/software ? I have a domain but I want when it accessed mydomain.com it should open the website which is a php application but when the access mydomain.com/yesmo it should open my other node.js application. So I was thinking of doing the same configuration using alias as you explained. – aidonsnous Aug 10 '17 at 15:39
1

Is it possible to have a different vhost for each application like that:

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.domain.tld
Alias otherApp /www/otherApp
</VirtualHost>
kmchen
  • 39
  • 5
  • This will not work as Apache will always choose the first virtual host that match with the ServerName directive. The second virtual host will not be used and thus the Alias directive will not be effective. As a result any call to `www.domain.ltd/otherApp` will issue an http _404 not found_ error. – Daishi May 29 '20 at 10:24
  • Would this work if we reverse the order? So it would find "www.domain.ltd/otherApp" first, and if not then find "www.domain.ltd"? – eyal_katz May 28 '21 at 19:24
0

I add to the alias.conf file (on a windows machine).
Remember that if it outside the 'document root' path, you'll need permissions

<IfModule alias_module>

    #### FolderPath ####
    Alias /folderpath "E:/any/path/you/like"

    <Directory "E:/any/path/you/like">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    #### Another ####
    Alias /another "E:/another/different/path"

    <Directory "E:/another/different/path">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

</IfModule>
DefenestrationDay
  • 3,712
  • 2
  • 33
  • 61