View all posts

How to disable directory listing with .htaccess

By default, Apache web servers will display the file contents of any directory that does not include an index file. For example, if your directory does not contain an index.html, index.php, or similar index file, Apache will display the folder contents for all to see.

This is bad for security and can let anyone view your sensitive files.

apacheautoindex

The easiest way to prevent directory indexing is to disable it in .htaccess.

Simply open your .htaccess file, or create a new file called .htaccess in your website root folder if you don’t have one.

Enter the following line and save the file:

# Disable Directory Indexing
Options -Indexes

That’s it!

Now when trying to view the same files, you’ll see a 403 forbidden message.

Related Articles...

Install LAMP

How to install LAMP Stack on Ubuntu 20.04

What is LAMP? The LAMP acronym stands for Linux, Apache, MariaDB/MySQL, and PHP, all of which are free and open source. It is the most commonly used software stack for dynamic websites and web applications. The operating system is Linux, the... Read more

This website uses cookies

We use cookies for the analysis of our visitor data, to improve our website, and to give you a great website experience. For more information about the cookies we use, please see our cookie policy.