2

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 127.0.0.1?

  • 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
1

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

127.0.0.1 app.localhost
127.0.0.1 app2.localhost

etc.

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

Update: I have no mac, but try 127.0.0.1 *.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 127.0.0.1 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.