1
 Apache version: 2.4
 OS: Ubuntu 14.04

I am not sure whether I wrote the heading correctly. My index file is located at some directory (say /var/www/html/new/ ) rather than the default apache root. I want apache to load the index file from this directory when I type localhost or my IP onto the address bar. I cannot use this (/var/www/html/new/ ) directory as the document root, since I have dependency files in /var/www/html/. I want apache to load the index file in the directory /new/ without altering the url. I mean when I type localhost It should load that index file and the url should not be localhost/new/

Is there any way to do this? Can it be made possible using .htaccess file? I am pretty new to this stuff. It would be helpful if someone could explain in simple terms.

UPDATE

I just read this is possible using apache url rewrite. Can somebody explain how to do this? Does it use htaccess?

  • Sounds like you need to change the DocumentRoot in you Apache config to `/var/www/html/new/`. Did you you try that? – Gmck Jan 19 '16 at 14:29
  • @Gmck I tried that. But as I have mentioned in question, I have some dependency files `/html/` folder itself. So the index file in `/new/` doesn't load properly. – Anonymous Platypus Jan 20 '16 at 07:20

1 Answers1

0

If you only have the index file in /var/www/html/new/ (e.g. /var/www/html/new/index.html) you could just do this with a symbolic link so your index file also appears in /var/www/html/

For example, first become the Apache user (so any files you create have the correct permissions):

sudo -s -u www-data
whoami
$ www-data

Create a symlink:

ln -s /var/www/html/new/index.html index.html

See what you get:

ls -l /var/www/html/

total 4
lrwxrwxrwx 1 www-data www-data   28 2016-01-19 14:36 index.html -> /var/www/html/new/index.html
drwxr-xr-x 2 www-data www-data 4096 2016-01-19 14:25 new
hillsy
  • 231
  • 2
  • 4
  • I tried this now. But it doesn't seem to be working. Instead of showing the index page it simply shows the directory listing :( – Anonymous Platypus Jan 20 '16 at 08:48
  • My example above assumes you've got index.html as (one of) the values for the DirectoryIndex directive. If you've got index.php (for example) you should adjust the ln command e.g. ln -s /var/www/html/new/index.php index.php – hillsy Feb 09 '16 at 13:35