I'm running MacOSX 10.11.4.
I'd like to have example.com point to my locally running apache server, but have www.example.com point to the actual website.
Example:
I have the following entry in my /etc/hosts file:
127.0.0.1 example.com
If I ping example.com and www.example.com, they both hit 127.0.0.1 (I believe because the canonical URL is recognized as being the same).
Interesting note, Chrome will pull the URL's as I want, but Firefox will hit localhost for both.
-
Edit: I know that using something like example.local is more conventional and avoids this problem entirely; however, my work has been using the www/non-www method for a while now and would like to keep it, if possible.
This might be too easy, but why don't you put
into your
/etc/hosts
file, with 123.52.232.12 being the IP address of the real example.com site?This is the default resolution order, with the
hosts
file autoexpanding for subdomains. The solution by @fragmentedreality provides a workaround by using the dnsmasq resolver, which is also recommended at https://serverfault.com/questions/431605/dont-automatically-include-all-subdomains-in-dnsmasq-address and described at https://gist.github.com/ogrrd/5831371.