Resolving adresses with “.localhost” TLD in macOS

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?

1

1 Answer

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.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like