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.


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...

How to sync server time

How to sync server time in CentOS & AlmaLinux

The NTP protocol synchronises the clocks of computers over a network. In this article, we will show you how to quickly sync the server time. Many systems-related tasks and processes require the correct timezone. For example, the cron daemon uses... 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.