Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 this example i'm trying to force to load localhost/project

However it doesn't work.

The above works, but I really need it to go to /project. Any idea?


locked by HopelessN00b Jan 21 '15 at 21:40

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as off-topic by HopelessN00b Jan 21 '15 at 21:40

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

This question is off-topic under current topicality rules. – HopelessN00b Jan 21 '15 at 21:40

/etc/hosts doesn't work that way. It's simply a mapping of IP address to name. Basically DNS in a text file. You need to configure your web server, whatever that is, redirect any requests to the root to go to /project. One way might be to set the document root to point directly to the /project folder.

I'm just trying to point a domain (any domain) to a subdirectory of my localhost. It's a development server. – user138795 Sep 28 '12 at 3:53

Edit edit/hosts with: root console matrix

Edit /etc/apache2/sites-enabled/000-default with:

<VirtualHost *:8080>
    ServerName [projectname]
    ServerAdmin webmaster@localhost
    DocumentRoot /home/count/Workspace/[projectname]/

    <Directory /home/count/Workspace/[projectname]/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

And finally set ports to listen to all with:

NameVirtualHost *
Listen 80
Listen 8080

Then reboot, and you can for example, have load localhost/[projectname]

Not sure why you people are saying it couldn't be done. :/ meh


Forget about /etc/hosts for this. /etc/hosts is the old way to answer 'which IP does this name belong to'. It has nothing to do with the way files or [web] services are organized.

If you want to manipulate web traffic, use a tool suitable for that. E.g. a proxy.


This needs to be done at web server level. However you do need the /etc/host entry without the slash project part. If you are using apache httpd as your web server then have a look at url rewrite tutorial. A simple example i think will work for you would be add the following to httpd.conf or some conf that the httpd.conf says include

RedirectPermanent /project

You need mod_alias module loaded in the httpd for this to work. Most probably you already have.