I know how to block websites in the host file and it works with others, but with YouTube i just can't get it to work. What am I missing?
127.0.0.1 youtube.com 127.0.0.1 www.youtube.com
127.0.0.1 loopback address to youtube.com or others except
localhost may cause some problems.
So map any unreachable IPv6 address is more better such like:
You may need to flush the cache by running
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Also, the entries in the hosts file need to be DNS names, not URLs (meaning the last two lines are wrong).
You need to restart the entire computer, not just Safari or flushing cache.