0

I have a subdirectory abc in the document root /var/www/html

I want to be able to run any file any_file.html within the subdirectory by typing in the browser:

localhost/any_file instead of localhost/abc/any_file.html or my_domain.com/any_file instead of my_domain.com/abc/any_file.html

I tried writing in httpd.conf:

<Directory "/var/www/html/abc">
RewriteEngine On
RewriteBase /
RewriteRule %{REQUEST_FILENAME} %{REQUEST_FILENAME}\.html
</Directory>

But it doesn't work. Options FollowSymLinks is activated in <Directory> so I believe I would not need to write this again. Does anyone knows why and how to solve it? Thanks.

Update: I have another subdirectory efg which I need to be able to access through localhost.

Question Overflow
  • 2,103
  • 7
  • 30
  • 45

3 Answers3

1

When declaring the Vhost for the domain, you need to add:

<VirtualHost *:80>
DocumentRoot /var/www/html/abc
     <Directory />
          *your options*
    </Directory>

</VirtualHost>

Now your / will be /var/www/html/abc

If your document structure is like this:

/
-abc
-edf

You will now by default access the abc folder. If you also want to access the edf folder you have two options:

  • Make another vhost for a subdomain who's documentroot is edf
  • Symlink the edf folder into abc

Symlinking is pretty straightforward (ln command). To make another vhost you can create a new file in your sites-available/ folder or add these entries at the bottom of your sites-available/default

DocumentRoot /var/www/html/efg ServerName efg.mydomain.com

if you made a new file you need to run:

a2ensite filename

and restart apache. Now when you visit the subdomain (don't forget it to add it to your dns server). It will use efg as it's documentroot.

Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
  • Thanks Lucas, I am testing it on my development server. The production server will be a dedicated server. Can I still implement your solution? I don't quite understand why document root is `/var/www`. Can you elaborate? – Question Overflow Apr 15 '12 at 08:07
  • I made a mistake sorry. Updated my answer. – Lucas Kauffman Apr 15 '12 at 08:16
1

Change the DocumentRoot from

/var/www/html

to

/var/www/html/abc
user9517
  • 115,471
  • 20
  • 215
  • 297
  • Thanks lain, I have thought about that, but I would like to be able to access to another subdirectory `efg` too. – Question Overflow Apr 15 '12 at 08:01
  • We're not mind readers - If you don't provide all of the relevant information then we can't be expected to give you the correct answer. You have 3 answers that all say the same thing, this is because we all answered the question as asked. – user9517 Apr 15 '12 at 08:04
  • Sorry for wasting your time. I have updated my question. – Question Overflow Apr 15 '12 at 08:09
1

You can change the directive

DocumentRoot /var/www/html

to be

DocumentRoot /var/www/html/abc

in the corresponding virtual host.

Another option is to use mod-rewrite to rewrite every path that starts with /abc to be without it.

Khaled
  • 36,533
  • 8
  • 72
  • 99