How to hide directory index from URL. (ex: http://www.yourdomain.com/wcf/ ) If you see file listing there, you may want to hide the index

  • I wanted to hide the folder structure from showing up on a webpage at www.mydomain.com/wcf/ and tried searching the forum But I wasn't able to come up with anything, or maybe I was using the wrong search terms.


    If you go to yourdomain.com/wcf/ and see a directory and files, you'll probably want to do what I did, and make it not index like that.


    EDIT: See second post for a better solution





    I'm on Debian linux with Apache.



    sudo nano /etc/apache2.conf


    ctrl+w then search for: <Directory


    edit the directory for the root of your domain and add Options -Indexes to it.



    then save the file and restart apache.
    sudo/etc/init.d/apache2 restart



    It may be good to make a copy of the .config file before changing in case you accidentally hit a key somewhere in the apache2.conf file while looking for the directory to edit.




    Now when i go to mydomain.com/wcf i get: Forbidden You don't have permission to access /wcf/ on this server

    Edited 4 times, last by Jungian: added edit ().

  • You don't have to do this via apache2- or vhost config (which cannot be edited on shared hosting for example). Instead, simply add a .htaccess in the wcf directory:


    Options -Indexes


    That's all :) It applies resursively. The "less beautiful (and non-recursive) way" would be to add an index.html to all affected directories.

  • You don't have to do this via apache2- or vhost config. Simply add a .htaccess in the wcf directory:


    Options -Indexes


    That's all :)

    A few results I did find while Googling showed more complicated url rewrites in .htaccess, I didn't find a solution as simple as yours.


    Thanks