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.
ping
in the terminal results in both going to 127.0.0.1. I would think the two problems (Firefox and the ping command) are related, although it may have nothing to do with the hosts file. – Burnsidesdscacheutil -q host -a name example.com
anddscacheutil -q host -a name www.example.com
report? That goes through the system resolver, so it should tell you what the OS level thinks is going on. – Bullbatdscacheutil -q host -a name www.apple.com
(it should list a bunch of aliases, and generally both ip_address and ipv6_address. Then trydscacheutil -q host -a name apple.com
, which should just list several ip_address entries. – BullbatLC_ALL=C cat -vet /etc/hosts
. The entry should look like either "127.0.0.1^Iexample.com$
" (if you used a tab to separate the IP from the name) or "127.0.0.1 example.com$
" (if you used a space). If it shows something else, you have something weird in the file and should fix that. – Bullbatname: example.com alias: www.example.com ip_address: 127.0.0.1
example.com is the same, except without the alias line. – Burnsideshost www.example.com
(which does direct DNS lookups, bypassing /etc/hosts) and see if it says "www.example.com is an alias for example.com". – Bullbat