-1

Objective: do http://test.local and get the index from testsite, do http://l4.dev and serve the index from lara4.

What I don't want is the first index from the virtual host listing it can find

How should multiple local sites be managed? - best practice - (apache version 2.2)

This Is what I added to the httpd.config (is this the best way, - to add it directly to httpd.config?)

   NameVirtualHost *:80

 <VirtualHost *>  
    DocumentRoot "/Users/redres/Webdev/lara4"  
    ServerName l4.dev
    ServerAlias www.l4.dev
</VirtualHost>
<VirtualHost *>  
    DocumentRoot "/Users/redres/Webdev/testsite"  
    ServerName test.local
    ServerAlias www.test.local
</VirtualHost>  
<VirtualHost *>   
    DocumentRoot "/Users/redres/Webdev"  
    ServerName localhost  
</VirtualHost>   

<Directory "/Users/redres/Webdev">
    Options All
    AllowOverride All
    Order allow,deny
    Allow from All
</Directory>

this is the hosts file

127.0.0.1   test.local
127.0.0.1   l4.dev
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

thanks

Richard
  • 97
  • 7

2 Answers2

1

You need to tell Apache which virtual host should be used for a given domain name, by adding the additional hostname as a ServerAlias to the virtual host.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
1

You will need a NameVirtualHost directive:

NameVirtualHost *
<VirtualHost *>  
    DocumentRoot "/Users/redres/Webdev/lara4"  
    ServerName l4.local
    ServerAlias www.l4.local
</VirtualHost>
<VirtualHost *>  
    DocumentRoot "/Users/redres/Webdev/testsite"  
    ServerName test.local
    ServerAlias www.test.local
</VirtualHost>  
<VirtualHost *>   
    DocumentRoot "/Users/redres/Webdev"  
    ServerName localhost  
</VirtualHost>   

<Directory "/Users/redres/Webdev">
    Options All
    AllowOverride All
    Order allow,deny
    Allow from All
</Directory>

http://httpd.apache.org/docs/2.2/de/vhosts/name-based.html

etagenklo
  • 5,694
  • 1
  • 25
  • 31