How to Stop Apache from Listing the Contents of My User Directories

How do I disable directory browsing?

Create an .htaccess file containing the following line:

Options -Indexes

That is one option. Another option is editing your apache configuration file.

In order to do so, you first need to open it with the command:

vim /etc/httpd/conf/httpd.conf

Then find the line: Options Indexes FollowSymLinks

Change that line to: Options FollowSymLinks

Lastly save and exit the file, and restart apache server with this command:

sudo service httpd restart

(You have a guide with screenshots here.)

How to disable directory indexing from apache2 when going to the server's root?

If it's only one directory that you want to protect from viewing contents, you can also just add an index.html or index.php that will show whenever someone browses to that directory.

Disable directory listing on apache; but access to individual files should be allowed

I really couldnt find a direct answer on internet ; even on apache documentation. Finally, could find the solution through few iterations; we need to use Options and the value should NOT contain Indexes.

<Directory "/usr/share/uploads">
Options Includes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

deny directory listing with htaccess

Options -Indexes should work to prevent directory listings.

If you are using a .htaccess file make sure you have at least the "allowoverride options" setting in your main apache config file.

How to restrict folder content listing in php

possible solutions:

  • place a file index.html or index.php in the directory
  • define in your httpd.conf Options -Indexes
  • place that line in .htaccess

personnally I prefer the 2nd line. There hardly ever is use for automatical listing of the files to a browsing visitor.

Stop Apache from serving content from apache root directory

You probably have the following directive in your httpd.conf:

Alias /error/ "/var/www/error/"

This just redirects all your error queries to /var/www/error (e.g. if you need www.example.com/error/README it would redirect me to one of the README in that director). Removing the alias should fix your problem.

If you are concerned about access to your other directories then I, as a complete newbie to apache, would recommend.

  1. Auditing your httpd.conf and removing any aliases that you don't need.
  2. Modifying your containers to have "Deny from all" and "AllowOverride None" in all of them.
  3. If you have selinux enabled, then remove the httpd security contexts from those directories.

Prevent access to files in a certain folder

Add this to the .htaccess file:

order deny,allow
deny from all


Related Topics



Leave a reply



Submit