Forum Moderators: phranque

Message Too Old, No Replies

directory browsing disable

How to use .htaccess to deny browsing of directories

         

Jimbobjones

12:49 am on Jan 3, 2005 (gmt 0)

10+ Year Member



Hello,

I am the webmaster for a scouting website and i have many directories for which people may browse and access content which should really only be displayed on pages (if you know what i mean). I am pretty sure you can use .htaccess to block directory browsing however i do not have the knowhow,

Please help

James

coopster

12:59 am on Jan 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Jimbobjones.

You can simple drop an .htaccess file in that directory with a directive setting of

Options -Indexes
Have a look at the following Apache documentation for more infommation:

mod_autoindex [httpd.apache.org]
DirectoryIndex [httpd.apache.org]

Jimbobjones

12:31 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



I have read the documentation on the apache website but it seems rather complicated ):, is there a way of directing someone to the homepage if they for example try to access the directory www.example.com/Home_files. Could you show me what exactly to write in the .htaccess file.

Many Thanks

[edited by: rogerd at 2:50 pm (utc) on Jan. 3, 2005]
[edit reason] examplified [/edit]

coopster

1:33 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What is the name of your per-directory override files? If it is .htaccess, then the file name in the directory must be exactly that, with no other file name extension. Also, you must be able to use per-directory overrides, are you sure that directive is set as well?

This tutorial should help:
Apache Tutorial: .htaccess files [httpd.apache.org]

kevinpate

1:46 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Extends a left arm and shakes hands with James.
I also operate a scout related site.

If the .htaccess file already exists, see if it contains lines like these up at the top of the file:

Options -Indexes
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

If it doesn't, you'll want to add those lines, or at least the first of the two lines.

If you don't have an .htaccess file yet, make one.
Open Notepad or some other text editor you have.
You can even start with just those two lines above.
Save the file to your harddrive, calling it
".htaccess" (use the quotes)

Then just transfer the saved file to the root directory of your website.

Kick me a stickymail and we'll swap url's if you want, because under our TOS here we don't self-promote sites here. may be aspell before I see it as I'm close to being out the door.

Jimbobjones

2:03 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



I copied the two lines that you suggested:

Options -Indexes
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

onto a word file, saved it as a text file then once loaded onto the root directory i renamed it .htaccess instead of .htaccess.txt. This made the homepage show a page called internal server error what to do?

kevinpate

2:24 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you haven't already, delete the .htaccess file. That will kill off the 500 error code
(Internal server error)

I've got to get gone down the road to my daily work, but someone else will be along and hopefully they are smarter than me.

coopster

3:49 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You won't need the IndexIgnore [httpd.apache.org] directive. The IndexIgnore directive adds to the list of files to hide when you are actually listing a directory. You are not going to list the directory.

The only line you should need is the

Options -Indexes
Also, why are you dropping the .htaccess file in your root directory? You said the images were in a subdirectory, right? Make sure you place the .htaccess file in the directory in which you do not want the file listings.

Jimbobjones

4:23 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



I have done exactly what you said, all it does when someone accesses that directory is present an internal server error message.

jdMorgan

4:45 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



James,

Welcome to WebmasterWorld!

If you're getting a 500-Server Error on Options, you'll need to contact your host and ask them to configure your account with

 AllowOverride Options 

at a minimum, or
 AllowOverride All 

if you can talk them into it.

Otherwise, you have two choices: You can create a page called "index.html" in that directory, presenting a "directory listing not allowed" message, or use a meta-refresh on that page to redirect the browser to some other page. Or, you can change hosting providers, looking for one that will allow you to properly control access to your site.

Jim

Jimbobjones

5:08 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



Jim,

Will contact uk2.net asap,

Thanks