Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In this example i'm trying to force test.com to load localhost/project test.com

However it doesn't work. test.com

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

share|improve this question

4 Answers 4

/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.

share|improve this answer
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 domain.com load localhost/[projectname]

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

share|improve this answer

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.

share|improve this answer

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 http://test.com

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

share|improve this answer

Your Answer


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