To prevent directory or folder listing in Apache web server, you can add the following line of code to the .htaccess
file in the directory that you want to prevent listing for:
Options -Indexes
This will prevent directory listing for the directory in which the .htaccess
file is located, as well as for any subdirectories under that directory.
Alternatively, you can also prevent directory listing by adding the following line of code to the httpd.conf
file, which is typically located in the conf
directory of your Apache installation:
<Directory /path/to/directory> Options -Indexes </Directory>
This will prevent directory listing for the specified directory and all of its subdirectories. You will need to restart Apache for the changes to take effect.