Preventing access to site's directory structure

They have: 8 posts

Joined: Oct 2006

I'm trying to find a simple way of preventing site visitors from viewing a directory structure ...... without resorting to passwords.

I have a number of sub-directories in the same main directory but I want those who visit sub-directory A to be unable to view or access other sub-directories.

At the moment, they simply type mysite/main-directory and they can view the full directory structure and can access any of the sub-directories from there.

Any help appreciated !

demonhale's picture

He has: 3,278 posts

Joined: May 2005

The simplest way is put an index.html on every subfolders you have, you can leave the index.html blank or write a message on it. That way, when people acces your subdirectories, they can only see the index.html, not the content of the directory. The complex way is to use htaccess on the folders... And if you have cpanel, you could activate the option to protect all subfolders and it auto generates the htaccess on these folders....

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

As demonhale mentioned, another way is by placing a file called .htaccess on your server. Just put the following line in it:

IndexIgnore */*'

Anyone please correct me if I'm wrong, but I believe you only need to put one copy of .htaccess at the highest level directory that you don't want to be browsable, then all the subdirectories won't be browsable either. If you want most subdirectories to not be browsable, but want some specific subdirectory to allow it, place a .htaccess file in that folder with the following line:

Options +Indexes'

.htaccess files are of extreme interest to me, though I haven't been able to dedicate as much time to playing with them as I like. So I have not actually done directory browsing blocking like this before, but it is my understanding that it works like that.

They have: 8 posts

Joined: Oct 2006

Worked brilliantly Tim ...... thanks for your help !

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.