steph
steph

Reputation: 31

.htaccess file. Can I block access to a directory without blocking access to the files within it?

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.

Upvotes: 3

Views: 4899

Answers (4)

Kevin
Kevin

Reputation: 1

You can log into your site manager and then you can use you index manager to say which folder you would like to protect. I just did mine

Upvotes: 0

Regis Frey
Regis Frey

Reputation: 888

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.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798746

Just put an empty index.html in the directory.

Upvotes: 2

Pascal MARTIN
Pascal MARTIN

Reputation: 401032

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.

Upvotes: 6

Related Questions