My Website is hosted on a shared Apache server. How can I deny access to directory content pages so if someone goes to the address www.mywebsite.com/directory they don't see the following:

Index of /directory

Parent Directory

  • mycontent/
  • moreofmycontent/

There are two common ways to prevent directory listing under Apache:

  1. Create or edit the file called .htaccess in your web server's root directory and add the line:

    Options -Indexes

  2. Put blank index.html files in each subdirectory.

The first option is probably the best, unless you're distributing open source projects (like WordPress), when it's a good idea to use the blank index.html method to make sure subdirectories won't be listed by default for other people who download your project as well.

| improve this answer | |
  • Perfect! Totally solved my problem. Using solution 1 for now, may have to use solution 2 at a later time if I use Wordpress or Drupal. Thanks for your help, Nick. – Jane Nov 19 '12 at 11:49
  • 1
    You're welcome. WordPress already uses the blank index.html files in all directories, so you shouldn't have to worry about it with WP. (I was one of the people who proposed they add them for security reasons.) I don't think Drupal uses blank index files, though. – Nick Nov 19 '12 at 11:55
  • 1
    While WordPress includes index.html files in it's folders to prevent browsing folders without an index. Other folders on your shared account my be browseable if you have not set the Options -Indexes in your .htaccess file. Hostmonster as of now doesn't set this in their htaccess file and all folders are browseable by default so be careful to double check all your folder or your root level htaccess file. – Anagio Nov 19 '12 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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