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

(1)I'm currently in the process of moving a project to a web host.

(2)I want to install the site into a sub-domain - ie.

(3)I've directed to a sub-directory of the server root: /sub/public_html

(4)/sub has 2 directories:

`public_html` - for the publicly traversable files & directories
`resources` - for sensitive documents

(3)I now want:

  (a)users to be able to visit `` and traverse the contents of `public_html`

  (b)users NOT to be able to traverse the contents of 'resources`

  (b)users NOT to be able to view the DIRECT/IMMEDIATE contents of the server root

My questions are:

(1) Can this be done with .htaccess?

(2) If so, how?


EDIT: meant /sub/public_html instead of just /sub

share|improve this question

The obvious answer is to change the server root of the subdomain to sub/public_html instead of public_html. If you don't want user to be able to access anything below that, don't include it the server root. Server-side scripts will still be able to access the directory.

That said, you can do that, with a performance penalty, in a .htaccess:

RewriteEngine On
RewriteRule ^public_html/ - [L]
RewriteRule ^resources - [R=403,L]
RewriteRule .* public_html/$0 [L,QSA]
share|improve this answer
Thanks for your input. However, what about stopping the issue of a user being able to view every thing by just traversing as – Fortisimo Aug 22 '10 at 23:24
@Tunji Apache won't allow that... – Artefacto Aug 22 '10 at 23:45

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.