How can I block the access of directory files?

ciril tomy

New Member
Messages
53
Reaction score
1
Points
0
Hi Friends!
I have a problem with my site that when I type my file name such as www.mysite.com/images/
All the images could be seen by everyone. Can anybody tell me to solve this issue.
I heard from someone that i can do it by .htaccess but I don`t know what to write...

I have to block all directory files access from public.
Please help me to solve this...

Thanks in advance.
 

oraya68

New Member
Messages
27
Reaction score
0
Points
0
Hi Friends!
I have a problem with my site that when I type my file name such as www.mysite.com/images/
All the images could be seen by everyone. Can anybody tell me to solve this issue.
I heard from someone that i can do it by .htaccess but I don`t know what to write...

I have to block all directory files access from public.
Please help me to solve this...

Thanks in advance.


Cyril you can add the rule Deny from all to your .htaccess file.

Kind regards
Oraya

PS here's a link that will explain it for you.

http://www.kavoir.com/2009/01/htaccess-deny-from-all-restrict-directory-access.html

Another PS
You may also want to disallow spiders/robots, from indexing your image folder also so you may want to create a robot txt.
To stop them indexing a single folder you would do it like this:
User-agent: *
Disallow: /foldername/

foldername being the image folder etc.
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
[sarcasm]Ooh yes, deny from all, that won't do anything bad![/sarcasm]
I suppose you're talking about directory listing? When you go to a directory that doesn't contain an index file, you get a list of all files in the directory?

The solution is easy, put a .htaccess file in the directory (or any parent directory of that directory) containing the following (or append it to the existing .htaccess document).

Code:
Options -indexes

Note: deny from all will block ALL access to all files in that directory. Including the access required to view images when you're allowed to.
 

oraya68

New Member
Messages
27
Reaction score
0
Points
0
[sarcasm]Ooh yes, deny from all, that won't do anything bad![/sarcasm]
I suppose you're talking about directory listing? When you go to a directory that doesn't contain an index file, you get a list of all files in the directory?

The solution is easy, put a .htaccess file in the directory (or any parent directory of that directory) containing the following (or append it to the existing .htaccess document).

Code:
Options -indexes

Note: deny from all will block ALL access to all files in that directory. Including the access required to view images when you're allowed to.

Yes well op did say he wanted to block all access from the public, so that would do it!! And like you pointed out he could add options. You'll note I also included a link for him to read up further.

Oh and by the way if he wanted to allow site to load images on a page, that can be done by adding the site ip...
Works fine for me!

Oraya
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
Yes well op did say he wanted to block all access from the public, so that would do it!! And like you pointed out he could add options. You'll note I also included a link for him to read up further.

Oh and by the way if he wanted to allow site to load images on a page, that can be done by adding the site ip...
Works fine for me!

Oraya

If you allow the IP of the site, then the site's server can access the images through http, but no user will be able to do so. You'd have to manually add all users to allow access to your images.
Furthermore, if you don't disable directory listing, anyone who is allowed to see any images is also able to view the directory index. As a result, the OP will have a lot of work and no solution.

Either I wouldn't want to visit your site or you've certainly included a link to the wrong information :nuts:
Have you even read and understood it yourself?
 
Top