How To Disable Directory Listing in Apache using Htacess

By default indexing is enabled in Apache web server.To disable the directory listing for a specific directory, create a .htaccess file in that directory and inset the following code on it.

Add the following code in your htacess file

 Options -Indexes

Options -Indexes will disabled the listing of files on the website.

Make sure .htaccess files is enabled on Apache server.By default .htaccess is disabled.

By Using Apache Virtual Host

If you do not want to create .htaccess files then add the following settings in Apache Virtual Host.

<Directory /var/www/public_html >
    Options -Indexes
</Directory>

Finally We need to restart the Apache service after making any changes in Virtual host to apply these changes.
sudo systemctl apache2 restart