10

I currently have all my websites as directories under /var/www. I would like to set up a virtual host http://foo/ that points to the /var/www/foo/foo directory (and still keep the default localhost behavior).

I added the following file, foo, to /etc/apache2/sites-available/:

<VirtualHost *:80>
    ServerName foo
    DocumentRoot /var/www/foo/foo

    # Other directives here
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/foo/foo>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

I then ran the following commands:

sudo a2ensite foo
sudo /etc/init.d/apache2 reload

But when I go to http://foo/ it still returns an ISP search page.

4 Answers 4

15

You need to edit your /etc/hosts file so that http://foo resolves to 127.0.0.1.

Edit the file /etc/hosts (with sudo/root) and add the following line:

127.0.0.1 foo
1

Checkout https://github.com/Aslamkv/vh :)

This tool lets you add and remove virtualhost in Ubuntu by doing every configuration for you. It is simple and easy to use.

Disclaimer: I am the author :P

0

For those using apache. You will need to

Ensure you have .htaccess in root path of the site you are hosting. Example /var/www
Update the /etc/apache2/sites-available/default

From

<Directory /var/www/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
</Directory>

To

<Directory /var/www/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
</Directory>

Hope this helps someone

1
  • Shouldn't the 2 directory blocks be different?
    – gion_13
    Mar 6, 2014 at 7:57
0

If you wish, you can have a look at the answer I've posted here:

https://stackoverflow.com/questions/12532263/apache-domain-for-localhost-to-access-folders-as-http-folder-local/12563570#12563570

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .