/etc/hosts file not redirecting

dnsNetwork

There are several questions about this, but none seem to address what I'm seeing.

After editing my /etc/hosts with vi with a test redirect, nothing is redirecting when I visit in a browser, including Safari, Chrome and Firefox. This is on MacOs Sierra.

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1   www.cnn.com/

the result of $ cat /private/etc/hosts shows the same contents.

I have tried flushing the cache two ways:

$ sudo killall -HUP mDNSResponder
$ dscacheutil -flushcache

I have also rebooted my machine.

How can I get my /etc/hosts file to redirect?

Best Answer

It's extremely picky about the format of the /etc/hosts file. You have a "/" after the domain name, and this will confuse it (actually, it'll think that's part of the host name, and since you're trying to connect to the host "www.cnn.com" not "www.cnn.com/", it just doesn't match). So just remove the "/" and you should be good. There's no need to reset any caches.