Welcome to Geeklog, Anonymous Friday, June 14 2024 @ 07:15 am EDT

Geeklog Forums

Preventing directory listing -- .htaccess modification


Status: offline

oskay

Forum User
Newbie
Registered: 09/14/06
Posts: 13
This has been discussed before, but I decided that I wanted to prevent directory listing. Here's the situation: If someone tries to go to some non-existing page like http://www.evilmadscientist.com/aslkhasgelkh , they get redirected to the 404.php page, which works quite well. The same thing happens if they request a non-existing page inside a subdirectory, like http://www.evilmadscientist.com/layout/aogylhasdg . That's good. However, if they just go to the directory itself, like http://www.evilmadscientist.com/layout/ , they instead get a plain directory listing without any redirection to the main web site. As Dirk said in that discussion (several years ago), the obvious solutions are to put a blank index.html file in each directory, or to modify the .htaccess file. I've done the latter and I'm very pleased with the result, so I'm putting it in both of my GL sites. Since I didn't see it written down elsewhere here, I thought that I should leave a note showing exactly how to perform this modification. In the GL public_html folder, if you do not have one already, make a new file called .htaccess In this file, put the following
Text Formatted Code

ErrorDocument 404 /404.php
ErrorDocument 403 /404.php
Options -Indexes
 
With this enabled, directory listing is disabled and generates a 403 (permission denied) error. The 403 error (as well as the 404-- not found) error are both directed to the 404 error page. This works very well because the existing 404.php error code describes what I want to say to someone that requests (effectively) an index.html file that is not there. So, now someone that goes to http://www.evilmadscientist.com/layout/ sees a nicely formatted "not found" type error page. Nice!
 Quote

All times are EDT. The time is now 07:15 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content