How to prevent parent directory listing inside root folder when queried in the URL with APACHE server

Viewed 140

In the .htaccess file when we type

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

If there is a directory that exists inside the root folder for example say errors. It will be shown if someone enters the URL. What can we do to prevent the opening of the parent directory structure directory in such a case? How to prevent exposing parent directory structure to the user in case of all the folders that exist in the root directory and queried inside the URL

like url= localhost/errors

Any command for that. I am using apache 2.4.46

1 Answers

To prevent directory listing you can use Options directive

  Options -Indexes

This will show a 403 forbidden error if you try to access a directory on your server.

Related