Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I tried writing in httpd.conf:

<Directory "/var/www/html/abc">
RewriteEngine On
RewriteBase /

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.

share|improve this question
up vote 1 down vote accepted

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

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


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

If your document structure is like this:


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

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.

share|improve this answer
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 8:07
I made a mistake sorry. Updated my answer. – Lucas Kauffman Apr 15 '12 at 8:16
Seems a great idea! Thanks :) – Question Overflow Apr 15 '12 at 8:28

Change the DocumentRoot from



share|improve this answer
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 8: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. – Iain Apr 15 '12 at 8:04
Sorry for wasting your time. I have updated my question. – Question Overflow Apr 15 '12 at 8:09

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.

share|improve this answer
Can you elaborate on your second option? I would like to try that. Thanks. – Question Overflow Apr 15 '12 at 8:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.