Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a nutshell, I would like to be able to open a browser and open but it actually loads http://localhost/path/to/

I am using Mac OSX 10.5, and not afraid to get my hands dirty with the terminal :)

I use Apache as my local server.

share|improve this question
Are you trying to serve web pages to the outside world, or are you only expecting the URL to work for your machine? – Stephen Jennings Jun 14 '10 at 2:37
Just for my own machine. It gets tiresome typing/remembering the full filepath to my local copy of whatever websites I'm working on. – Austin Hyde Jun 14 '10 at 2:39
up vote 18 down vote accepted

Just to be clear, I'm basing this on the assumption that you really do want to load the literal web page http://localhost/path/to/ In other words, this will only work for this machine. If, on the other hand, you're trying to serve web pages to the outside world using your Mac OS X machine, then that's a different question.

First, add a new line to your /etc/hosts file:

You can do this by running the command sudo nano /etc/hosts, add this line to the end, then save it by pressing Ctrl-X, Y.

How you actually redirect/alias the address to http://localhost/path/to/ depends on which web server you're using. Assuming you're using Apache:

If you want the user's browser to show, then you want to set up a virual host and your httpd.conf file should have something like the following:

<VirtualHost *:80>
DocumentRoot /www/path/to/

If, on the other hand, you want the web browser's location bar to change to http://localhost/path/to/, then instead you will want to use mod_rewrite to create a redirect:

RewriteCond %{HTTP_HOST}   !^local\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/?(.*)         http://localhost/path/to/$1 [L,R,NE]
share|improve this answer
This won't go to a certain path though – John T Jun 14 '10 at 2:13
@John you're right, fixed. – Stephen Jennings Jun 14 '10 at 2:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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