Aliasing http://localhost

January 11th, 2008

When working on multiple rails apps I’ve been annoyed that the URL field in the browser gets cluttered during autocomplete. My autocomplete for http://localhost:3000/ will have paths for each app I’ve worked on recently. Since the browser just sees them all as http://localhost:3000 it returs all the matches. Same problem for form auto-complete and 1password auto-complete.

There’s an easy way around this.

on a Mac or other *nix

Edit /etc/hosts and add one line per project. Here’s my /etc/hosts:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
127.0.0.1 cc
127.0.0.1 mlk
127.0.0.1 si

255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost

cc, si and mlk are abbreviations for sites I’m currently working on. With this in place I continue to start rails as ./script/server and it listens on localhost port 3000. But now when I’m working on ‘cc’ I point my browser at http://cc:3000. This makes it such that all autocompletes are now only for the ‘cc’ app. I find it a great benefit for such little effort.

Windows

Updated 1/12/07

Andy Kim commented that the windows hosts file is at C:\WINDOWS\System32\Drivers\etc\hosts

1 Response to “Aliasing http://localhost”

  1. Andy Kim Says:

    Great tip.

    On Windows it's C:\WINDOWS\System32\Drivers\etc\hosts

Leave a Reply