1

Currently this is my httpd-vhosts.config file

NameVirtualHost *:80

<VirtualHost *:80>
    VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
</VirtualHost>

However I would like to have access to localhost too to be able to view it on the same network using the computer IP. so I tried this

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName localhost
  VirtualDocumentRoot /Users/Gabri/Sites/
</VirtualHost>


<VirtualHost *:80>
    VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
</VirtualHost>

but it only directs to localhost how can I fix this?

ahmedelgabri
  • 111
  • 1

3 Answers3

0

Your other site needs another servername. And your DNS must know of it!

<VirtualHost *:80>
    VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
    ServerName Something
</VirtualHost>
Jensd
  • 147
  • 9
  • I want to keep it flexible I don't want it to have just one name, cause actually under `Sites/` folder there are many sites each in each own directory. so right now for example I have `Sites/dev/sitesname/build` I write `sitename.dev` & it works, will it still work like this with your solution? – ahmedelgabri Apr 26 '13 at 17:15
  • Check out this http://httpd.apache.org/docs/2.2/vhosts/mass.html – Jensd Apr 26 '13 at 17:18
  • 1
    By the way: maybe you should edit the question so it more reflects what you want! – Jensd Apr 26 '13 at 18:08
0

I have the same problem but doing something like this fixed it for me, the only problem that if I created a new folder under sites I have to go and edit httpd-vhosts.conf file again. I hope there is an easier way to do this.

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot /Users/<username>/Sites/
  ErrorLog "logs\errors.log"
</VirtualHost>

<VirtualHost *:80>
  ServerAlias *.dev
  VirtualDocumentRoot /Users/<username>/Sites/dev/%1/build
</VirtualHost>

<VirtualHost *:80>
  ServerAlias *.wordpress
  VirtualDocumentRoot /Users/<username>/Sites/wordpress/%1/public
</VirtualHost>

<VirtualHost *:80>
  ServerAlias *.localhost
  VirtualDocumentRoot /Users/<username>/Sites/localhost/%1/www
</VirtualHost>
John
  • 1
0

You need to add a ServerName and ServerAlias in your case you'll probably also need a wildcard :

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName localhost
  VirtualDocumentRoot /Users/Gabri/Sites/
</VirtualHost>

<VirtualHost *:80>
   ServerName default.localhost
   ServerAlias default.localhost * 
   VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
</VirtualHost>
Stack 101
  • 101
  • 3