Take the 2-minute tour ×
Server Fault is a question and answer site for 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

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?

share

locked by HopelessN00b Jan 21 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 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 at 21:40

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

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

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

share

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