I have this website, example.com, and I just discovered that I can access my folders through the URL (for example, I can access the img folder using a web browser by going to http://example.com/img ). It's crazy! I'm sorry, I can't even search for the proper term in Google/StackOverflow because I don't know what it's called or what the proper term is. Also, I am using tags generously because I'm not sure what categories this would fall under.
3 Answers
put Options -Indexes
in your .htaccess to prevent directory listing
... or deny from all
if you want to restrict access to files

- 2,319
- 4
- 30
- 49
Add the following line to a file named .htaccess
in the root of your site with the following line
Options -Indexes
It will prevent Apache from listing the contents of the directories to your visitors and should still allow you to reference files within them (ie images) in your HTML.

- 3,065
- 1
- 16
- 27
You can do it in either two ways. First is to create an index.html
file and store it in the directory, so that whenever anyone tries to navigate that directory through the URL he'll see the index.html
page. And the second option would be to create a .htaccess file inside the directory and place this line of code inside it: Options -Indexes
. I would recommend adding a 404 Not Found page with header informations, like what most of the websites are already doing.

- 126
- 6