I find it confusing to work on my site locally when there's something like "localhost:80" in the adress bar. It would be much better to have something like "mydomainoffline.com" which then maps somehow to "localhost:80", if possible. How would I do that on the MAC?

I use the free MAMP package (mamp.info), not the commercial MAMP PRO. So I need to do that sort of thing by hand. How can I do that?

  • You can drop the ":80" as that's the default port assumed by the browser.
    – Chris Nava
    Dec 21, 2009 at 14:53

5 Answers 5


I realize that the OP has a mac, and that the solutions given work for both mac and linux.

But I would also like to add that Windows has a hosts file too in C:\Windows\System32\drivers\etc\hosts, in case someone comes here through google with the same problem and uses windows :)

  • +1 for being nice to non-macists :-)
    – nikc
    Dec 21, 2009 at 12:20

The Webserver can't do that for you, as it's not responsible for DNS resolution.

You'll need to add an entry to your Hosts file (/private/etc/hosts or /etc/hosts depending on the version), and then perform some special MacOS X magic ritual to make it stick.

  • Leopard (10.5) (and presumably 10.6) has no niload so I'm not sure if this applies any more.
    – Ben James
    Dec 21, 2009 at 12:26

You can do this by editing /etc/hosts (you will need to do this as administrator, e.g. sudo nano /etc/hosts

Find the line that looks like:    localhost

And add another hostname, e.g.    localhost mydomainoffline.com

(Edit: I should point out that while this works just fine for Leopard (10.5), I don't know about other versions of Mac OS X)


Edit your HOSTS file (/etc/hosts) Replace localhost by the desired name

And you don't need to have :80 because it is the default HTTP port anyway

Finder->Go To-> /etc/

Then open up the hosts file with TextEdit and do what I said above

  • Given that the OP is using a Mac OS X package, I don't think they'll find a hosts file there.
    – Quentin
    Dec 21, 2009 at 12:13
  • 5
    There is absolutely no need to replace the localhost entry with something else; in fact, this is a bad idea and could break a lot of things.
    – Ben James
    Dec 21, 2009 at 12:19
  • 2
    Still not correct, the path is different on MacOS, and editing the file is not sufficient. Besides, I would advise very much against replacing the localhost entry, because a lot of programs depend on localhost being there. Dec 21, 2009 at 12:19
  • 1
    I would not recommend replacing localhost - you could instead append another domain name for localhost.
    – Anonymous
    Dec 21, 2009 at 12:20
  • 5
    did anyone mention that it's not a good idea to replace localhost ?
    – pavium
    Dec 21, 2009 at 12:23

I don't use MAMP, but I have done the same thing using the pre-installed Apache 2. There may be a simpler way to do this, but this has really helped me with testing multiple sites in my local machine.

Edit host file

The host file is located at /etc/hosts. I end all of my local test domains with local, but this isn't required. Here's a sample of what I have.

# clients       acmewidgets.clients.local       someclient.clients.local       etcetc.clients.local

# Projects and mini sites       someproject.proj.local       someotherproject.proj.local

# tools   sql.tools.local

# Different open source solutions
    # e-commerce       magento.apps.local       opencart.apps.local       oscommerce.apps.local       zencart.apps.local
    # forums       vanilla.apps.local
    # blogs       wp.apps.local       wpmu.apps.local
    # CMS's       joomla.apps.local       drupal.apps.local       concrete5.apps.local

So not only do I have different client sites, but you can see that I have a subset of open source platforms that I routinely use and test against, as well as personal projects and tools.

Also, note that it's not a good idea to replace localhost, as some other applications are likely to use it. You should just add

Edit virtual hosts

Again, I don't use MAMP so I don't know where it's stored, but you're looking for the http-vhosts.conf file. In the standard OS X install, it's located at /etc/apache2/extra/httpd-vhosts.conf

For every *.local domain that I've created in my host file, I've created a respective virtual host entry.

NameVirtualHost *:80

# Open source app testing
# ----------------------------------------------------------------------

<VirtualHost *:80>
    ServerName opencart.apps.local
    DocumentRoot /Users/justin/Development/localhost/opencart/html

<VirtualHost *:80>
    ServerName oscommerce.apps.local
    DocumentRoot /Users/justin/Development/localhost/oscommerce/html

# Tools
# ----------------------------------------------------------------------

<VirtualHost *:80>
    ServerName sql.tools.local
    DocumentRoot /Users/justin/Development/localhost/bin/tools/wwwsqldesigner

* You may have to change the permissions on either of these files to be able to save your changes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .