How do I disable directory browsing?

后端 未结 12 593
灰色年华
灰色年华 2020-11-22 08:35

I want to disable directory browsing of /galerias folder and all subdirectories

Index of /galerias/409

* Parent Directory
* i126937298         


        
相关标签:
12条回答
  • 2020-11-22 09:13

    This is not an answer, just my experience:

    On my Ubuntu 12.04 apache2, didn't find Indexes in either apache2.conf or httpd.conf, luckily I found it in sites-available/default. After removing it, now it doesn't see directory listing. May have to do it for sites-available/default-ssl.

    0 讨论(0)
  • 2020-11-22 09:16

    The best way to do this is disable it with webserver apache2. In my Ubuntu 14.X - open /etc/apache2/apache2.conf change from

    <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>
    

    to

    <Directory /var/www/>
            Options FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>
    

    then restart apache by:

    sudo service apache2 reload
    

    This will disable directory listing from all folder that apache2 serves.

    0 讨论(0)
  • 2020-11-22 09:17

    One of the important thing is on setting a secure apache web server is to disable directory browsing. By default apache comes with this feature enabled but it is always a good idea to get it disabled unless you really need it. Open httpd.conf file in apache folder and find the line that looks as follows:

    Options Includes Indexes FollowSymLinks MultiViews
    

    then remove word Indexes and save the file. Restart apache. That's it

    0 讨论(0)
  • 2020-11-22 09:18

    Apart from the aformentioned two methods (edit /etc/apache2/apache2.conf or add Options -Indexes in .htaccess file), here is another one

    a2dismod autoindex
    

    Restart the apache2 server afterwards

    sudo service apache2 restart
    
    0 讨论(0)
  • 2020-11-22 09:19

    Add this in your .htaccess file:

    Options -Indexes
    

    If it is not work for any reason, try this within your .htaccess file:

    IndexIgnore *
    
    0 讨论(0)
  • 2020-11-22 09:22

    To complete @GauravKachhadiya's answer :

    IndexIgnore *.jpg
    

    means "hide only .jpg extension files from indexing.

    IndexIgnore directive uses wildcard expression to match against directories and files.

    • a star character , it matches any charactes in a string ,eg : foo or foo.extension, in the following example, we are going to turn off the directory listing, no files or dirs will appear in the index :

      IndexIgnore *

    Or if you want to hide spacific files , in the directory listing, then we can use

    IndexIgnore *.php
    

    *.php => matches a string that starts with any char and ends with .php

    The example above hides all files that end with .php

    0 讨论(0)
提交回复
热议问题