prevent view of web directory contents

  • mk27
  • Proficient
  • Proficient
  • User avatar
  • Posts: 334

Post 3+ Months Ago

Given a web address such as http://www.here, if I go to http://www.here/there, I will get the index page, or if there is no index.html, I'll get a directory listing.

Is it possible to get a directory listing even if there is an index.html? More importantly, if that is possible, can you prevent it?

Maybe this is an apache configuration question...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

That's a server thing.

In your case with Apache it is indeed a configuration option. If you set the -Indexes flag for Options, it will hide indexes, like so:

Code: [ Select ]
<Directory />
Options -Indexes
</Directory>
  1. <Directory />
  2. Options -Indexes
  3. </Directory>


(You can also use .htaccess obviously)

For the extremist, I've found such things as this, just in case the server configuration changes.

PHP Code: [ Select ]
<?php
 
send_404();
 
function send_404()
{
   header('HTTP/1.x 404 Not Found');
   print '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'."\n".
   '<html><head>'."\n".
   '<title>404 Not Found</title>'."\n".
   '</head><body>'."\n".
   '<h1>Not Found</h1>'."\n".
   '<p>The requested URL '.
   htmlspecialchars(str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']),ENT_QUOTES).
   ' was not found on this server.</p>'."\n".
   '</body></html>'."\n";
   exit;
}
 
?>
  1. <?php
  2.  
  3. send_404();
  4.  
  5. function send_404()
  6. {
  7.    header('HTTP/1.x 404 Not Found');
  8.    print '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'."\n".
  9.    '<html><head>'."\n".
  10.    '<title>404 Not Found</title>'."\n".
  11.    '</head><body>'."\n".
  12.    '<h1>Not Found</h1>'."\n".
  13.    '<p>The requested URL '.
  14.    htmlspecialchars(str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']),ENT_QUOTES).
  15.    ' was not found on this server.</p>'."\n".
  16.    '</body></html>'."\n";
  17.    exit;
  18. }
  19.  
  20. ?>


Hope this helped.
  • mk27
  • Proficient
  • Proficient
  • User avatar
  • Posts: 334

Post 3+ Months Ago

PolishHurricane wrote:
Hope this helped.


Yep! Thanks!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 3 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.