views:

261

answers:

3

I have a directory on my webserver. It does not have an index page. so when u access the directory via a web browser it lists the files in it. Now i want to create a htaccess file that can block the directory listing so that when you access it via the web browser, the files in the directory would not be listed but would be able to access the files by appending the name of the file you wish to access to the url making it a full part to the file. Also the htaccess file should be able to restrict access from all but files with a particular extention. Thanks.

+2  A: 

You can turn off the file listing for a particular directory in the directory's .htaccess with

Options -Indexes

OR

You could just put an empty index.html file in the directory you want to protect.

Lenni
+7  A: 
Options -Indexes

Order allow,deny
Deny from all

<Files "*.gif">
    Allow from all
    Deny from none
</Files>
Adam Backstrom
thanks for the response. And if i want to include multple viewable files, can i seperate them with |
War Coder
Right, with regex: <Files ~ "\.(gif|jpe?g|png)$">. That example is directly from the Apache docs: http://httpd.apache.org/docs/2.2/mod/core.html#files
Adam Backstrom
thanks so much,u saved so much of my time.
War Coder
A: 

In the .htaccess file in your directory just put

Options -Indexes

As stated before.

Edited to remove the wrong htaccess setting. Again sorry

M_D_K
-1 it'll also block all access to all the files, though.
David Zaslavsky
Sorry I misread.
M_D_K