1
vote

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?

1
  • This question is off-topic under current topicality rules. Jan 21, 2015 at 21:40

4 Answers 4

5
votes

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

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

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

0
votes

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.

0
votes

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.