1

I'm new to configuring my Mac for localhost so this may be a dumb question. I want to set up a virtual host so that http://localhost/domain points to http://domain.dev. In my Apache configuration, I have localhost pointing to my Sites folder. That works correctly. I can browse to localhost/domain.

In my hosts file, I set up domain.dev as 127.0.0.1.

In my vhosts file, I set up the following entry:

<VirtualHost 0.0.0.0:80>
DocumentRoot "/Users/username/Sites/domain/"
ServerName domain.dev
</VirtualHost>

But when I uncomment this line in the Apache configuration:

Include /private/etc/apache2/extra/httpd-vhosts.conf

The browser adds "www" to the domain.dev, which it then can't find. What am I doing wrong?

sehummel
  • 113
  • 4

1 Answers1

0

Just use ServerAlias.

<VirtualHost 127.0.0.1:80>
   DocumentRoot /Users/username/Sites/domain/
   ServerName domain.dev
   ServerAlias www.domain.dev
</VirtualHost>
tacotuesday
  • 1,389
  • 1
  • 16
  • 27
  • I'm getting an error that the server www.domain.dev cannot be found. I restarted Apache. – sehummel Nov 21 '12 at 17:55
  • Shouldn't there be a way to prevent it from adding the "www"? – sehummel Nov 21 '12 at 17:59
  • Try just putting in the IP address for localhost (127.0.0.1), or just putting in `localhost`. Unless you're running a DNS server and have added the `domain.dev` domain as an `A` record in a zone file, it won't resolve. – tacotuesday Nov 21 '12 at 18:03