How do I use .htaccess to stop webserver listing all files in directory?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alien
    New Member
    • Sep 2007
    • 61

    How do I use .htaccess to stop webserver listing all files in directory?

    Hi guys,

    Currently in my webserver I got a directory call: ..../htdocs/upload/

    Currently, all files are listed when users go to www.mysite.com/upload/

    The way it works, when user click on a file link in my system, they redirected to this directory like this:



    So If I have

    Code:
    deny from all
    It stops listing all files but in the process doesn't allow me to view files when I click on the link.

    Is there a way I can tweak it so when users directly go to

    www.mysite.com/upload/
    they get 403 error BUT if they go they go to:
    http://mysite.com/upload/invoice.txt
    they don't get 403 error?

    Thanks.
  • Alien
    New Member
    • Sep 2007
    • 61

    #2
    Using
    Code:
    IndexIgnore *
    worked for me.

    I can still open files directly without seeing the index listing when I just do upto /upload

    Comment

    • Luuk
      Recognized Expert Top Contributor
      • Mar 2012
      • 1043

      #3
      You could also put an empty index.html file in that directory.
      (or one with some text, explaining why there's noting to see there...)

      Or the following index.php:
      Code:
      <?php
              header('Location: ..');
      ?>

      Comment

      Working...