22

I do not want to use .htaccess. How should I change my Directory attributes?

<VirtualHost *:80>
   ServerName abc.com
   DocumentRoot /usr/share/uploads
   <Directory " /usr/share/uploads">
      Order allow,deny
      Allow from all
   </Directory>
</VirtualHost>
Deepak Singhal
  • 10,568
  • 11
  • 59
  • 98

6 Answers6

55

If you are using Debian/Ubuntu, just go to terminal and type

sudo a2dismod autoindex
sudo service apache2 restart

If you are using Centos/Fedora, just do:

mv /etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/autoindex.bkp
/etc/init.d/httpd restart

And similarly in other OS or distros...

This should disable the apache module that makes those fancy (normally useless and a security problem) directory listings. Also, as a bonus, you earn a bit of performance :-)

Natxet
  • 1,334
  • 3
  • 12
  • 18
  • Can't get easier then this solution – Gajotres May 01 '14 at 21:37
  • or in wamp (on windows) in httpd.conf put "#" in front of Include conf/extra/httpd-autoindex.conf and LoadModule autoindex_module modules/mod_autoindex.so – Alex Novikov May 12 '14 at 13:24
  • 1
    I've edited every single configuration file across my entire server and couldn't get those directory index pages to stop. This did the trick. You should have the accepted answer. – SeniorShizzle Jun 04 '15 at 19:33
27

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>
Deepak Singhal
  • 10,568
  • 11
  • 59
  • 98
  • 7
    The relevant documentation is the [Options](http://httpd.apache.org/docs/current/mod/core.html#options) section of the core feature page, which describes the affects of the "Indexes" option. You can also disable/enable individual options by prefixing them with -/+, without affecting any other options previously set: `Options -Indexes`. – outis Oct 14 '13 at 20:30
7

The @Deepak solution did not worked for me. This one did:

In the main apace configuration /etc/apache2/httpd.conf just add:

<Directory />
        Options FollowSymLinks
        AllowOverride All
</Directory>

And it will work for all of you domains and subdomains. Without .htaccess file.

Jevgenij Dmitrijev
  • 2,228
  • 1
  • 15
  • 23
1

All done above, but the directory info is still coming up? If you use index.php, rather than index.html, Check the following:

<IfModule dir_module>
    DirectoryIndex index.php
</IfModule>
json4rest
  • 21
  • 1
0

on my AWS ec2, i did this and it worked for me.

First open /etc/httpd/conf/httpd.conf file.

modify/add

<Directory /var/www/html>
   Options Indexes FollowSymLinks
   AllowOverride All
   Require all granted
</Directory>
Badmous
  • 95
  • 1
  • 5
-1

The easiest way would be to put an empty index.html (or whatever you apache is configured to deliver by default) inside that directory. This is not a real solution but a very simple workaround. The user browsing that directory would just see a blank white page.

Further you could use a script (like index.php) wich emulates the directory-listing and only shows some special files.

fragmentedreality
  • 1,287
  • 9
  • 31