Tuesday, November 6, 2018

apache 2.2 - Mac OS X Mountain Lion adding www to virtual host on localhost



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:




DocumentRoot "/Users/username/Sites/domain/"
ServerName domain.dev




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?


Answer



Just use ServerAlias.





DocumentRoot /Users/username/Sites/domain/
ServerName domain.dev
ServerAlias www.domain.dev


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...