1

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

127.0.0.1/project test.com

However it doesn't work.

127.0.0.1 test.com

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

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208

4 Answers4

5

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

Starfish
  • 2,716
  • 24
  • 28
  • I'm just trying to point a domain (any domain) to a subdirectory of my localhost. It's a development server. –  Sep 28 '12 at 03:53
1

Edit edit/hosts with:

127.0.0.1 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
    </Directory>
</VirtualHost>

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

ditto
  • 111
  • 1
0

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.

Hennes
  • 4,772
  • 1
  • 18
  • 29
0

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.

bagavadhar
  • 538
  • 4
  • 14