views:

125

answers:

3

I'm building a website, but I'm not entirely sure what to do with the .htaccess file. Say for example I have a folder called pages which holds all my pages, can i deny access to someone if they type in www.website.com/pages so that they can't see the directory? I've tried putting the .htaccess file in the pages folder with the "deny from all" line and although it denies access, it's also denying access to the actual pages. Is there a way to do this without denying access to see the pages on the website, just denying access to the directory?

Sorry if this doesn't make much sense, I'm so confused lol. Thanks for any help.

+4  A: 

If you don't want Apache to display the list of files in the directory, you can use

Options -Indexes

To disable the indexes feature.

See the Options Directive section of Apache's manual, for more informations.


Else, an "easy way" would be to just put an empty index.html or index.php file -- i.e. a default file that Apache uses when one is trying to access a directory.

About that, see the DirectoryIndex Directive.

Pascal MARTIN
+1  A: 

Just put an empty index.html in the directory.

Ignacio Vazquez-Abrams
A .htacess with "Options -Indexes" is much easier since it's (or can be, I think you can change that if you want) recursive. Just one file in your web server document root, and none of your directories can be browsed. Then you just have to put a .htaccess with "Options +Indexes" to authorize listing for a given directory if you want to. This way, it will even work for new folders you will add afterwards without having to do anything more.
Zed-K
A: 

Most hosts I've used do it with the IndexIgnore * directive. just put that in a .htaccess file and drop it into the folder you want to block indexing of. More info: Apache IndexIgnore Documentation.

Regis Frey