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 many directories in a application like


I have placed index html file in every folder to make it simple secure. But i think there must be some better and more secure technique for security.

my question is how can we do it through htacess and php.

share|improve this question

migrated from May 1 '12 at 1:46

This question came from our site for professional and enthusiast programmers.

Move everything that doesn't need to be under the document root out.

share|improve this answer

Remember that you do not need to have all of your files in the publicly accessible part of your server's directory structure. Say you have your document root in:

You can move things that the public doesn't need to see to:


You can still refer to these places in your code (as it uses the server's directory structure), but other people won't be able to access it as its outside your document root.

share|improve this answer

I would as Andrew, list them as /includes/ or /data/, but putting an index.html will still be a good idea. Depending on what you use the files for you can use IP-security. $_SERVER['REMOTE_ADDR'] == "your ip" in a simple if, of course if this in some sense should be publicly available this will not be a security.

share|improve this answer
i used simple technique. changed index.html to index.php. it contains header('location:/site-name/index.php'). it works... – shuja Apr 30 '12 at 10:55
But that wouldn't prevent them from accessing /data/secret.php, would it? – mikkeljuhl Apr 30 '12 at 11:10
mikkeljuhl, yes you are right .... – shuja Apr 30 '12 at 12:55
Options -indexes

this will would have the same effect as putting a index.html file in every folder, so people would have to guess the url, instead of getting a nice list of filenames.

To protect the includes folder (and possibly the data as well) you could put a .htaccess file inside in that contains:

Order allow,deny
Deny from all
Satisfy All

This way nobody can access those files from the internet, only PHP can include/read them.

share|improve this answer

Your Answer


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