When developing a web app locally I like to use addresses like app.localhost:8080 to access them. They work fine in Chrome but not in Safari. I guess this is because Chrome has special handling for the TLD and Safari uses the OS DNS resolver.

Is there a way to make macOS resolve all .localhost addresses to

  • Why would you want to use .localhost when .local is the traditional way stuff like this is done? The convention of app.local:8080 is the accepted way to have a locally networked address; localhost should only ever be used for pure local loopback needs. – JakeGould Jul 22 '16 at 15:22

Yes, as the root you should edit your /etc/hosts file and add line(s) like app.localhost app2.localhost


If it doesn't work immediately then restart browser/reboot.

Update: I have no mac, but try *.localhost. For my Linux it does NOT work, then the only way is to set up a DNS server on your box and configure 'localhost' zone on it.

  • What I'm really looking for is a way to have all the .localhost addresses resolve to without having to add them separately to hosts. – Hilzu Jul 22 '16 at 9:13
  • @Hilzu updated. – Putnik Jul 22 '16 at 15:17
  • @Hilzu There is a RFC proposal for this and some browsers (Chome, Opera) already do this internally: webmasters.stackexchange.com/questions/88636/… – Ronald Sep 4 '18 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.