Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent directory access

I have this current directory structure

myproject
  --> application
  --> assets
  --> data
  --> scripts
  --> styles
  --> system
  --> .htaccess
  --> favicon.ico
  --> index.php

I store my users uploaded images, videos on the data directory, and it has this structure:

data
  --> 5
      --> thumbs
      --> user_images
  --> 6
      --> thumbs
      --> user_images
  --> index.html

I placed index.html to prevent directory access. I can do this to all the data subdirectories to have the same effect, however is there a way to have this handled by .htaccess? I tried Deny from all rule in the .htaccess but it also won't allow me to use my images in my system. All I want to achieve is to prevent directory access (when direct access from URL) from my data directory. How is that?

like image 862
fishcracker Avatar asked Aug 01 '12 08:08

fishcracker


People also ask

Why should you disable directory access for your server?

Directory listing is a web server function that displays the directory contents when there is no index file in a specific website directory. It is dangerous to leave this function turned on for the web server because it leads to information disclosure.

Why am I getting a directory listing instead of my site?

If you are expecting to see an existing site however, and instead you see the directory listing something has gone wrong somewhere. The file may have been infected via a php injection attack and removed by a malware scanner. The site may have been attacked. Your account password may not be very secure.


1 Answers

In your .htaccess, add the following line:

Options -Indexes

See the manual for further details.

like image 120
MvG Avatar answered Sep 22 '22 07:09

MvG