Forum Moderators: phranque

Message Too Old, No Replies

how to block user to see my directory structure

         

prodriguez021

2:12 pm on Oct 13, 2005 (gmt 0)



Hi, I'm new to Apache and I'm using 1.3. I have developed a PHP application and I am able to see the directory structure of my application. I am wondering what the right way to block it. For example, if my application resides in [192.168.1.2...] if I type [192.168.1.2...] I see all my files and some of them can be opened and read in the browser.

I would be appreciated if somebody with more experience could give me a hint. Thanks.

Paul

jdMorgan

2:59 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Paul,

Welcome to WebmasterWorld!

Using NotePad or a similar simple text editor, create a plain-text (US-ASCII) file named ".htaccess" in that directory, or in any Web-accessible directory above it.

Place the following directive in that .htaccess file:


Options -Indexes

This will "forbid" access to the directory listing.

Another alternative is add a line of code to that .htaccess file to define the index.php file as the 'default index' for that directory. In this case, entering either http://192.168.1.2/myapp/index.php or http://192.168.1.2/myapp would display the index.php page:


DirectoryIndex index.php

For purposes of SEO and usability, the second option is usually preferred, so that it is not necessary for you or your visitors to include the "index.php" part of the URL in order to access index.php. You'll notice that the home pages of most big sites do not actually have a page name in the URL. This also allows you to later change your technology without having to change all your links to, say, index.asp or index.jsp.

See Apache core Options [httpd.apache.org] and Apache mod_dir DirectoryIndex [httpd.apache.org].

Jim

prodriguez021

7:24 pm on Oct 14, 2005 (gmt 0)



Thanks very much Jim. Really appreciate you help.