.htaccess file not being read ("Options -Indexes" in .htaccess file not working)

I had the same problem. I was using a virtual host so I modified httpd-vhosts.conf so if you are using one this could help

Where you configure your host reference the directory tag to be the same as your document root

<VirtualHost *:8080>
ServerName somelocalserver
DocumentRoot "C:/Websites/htdocs/yoursite"
<Directory "C:/Websites/htdocs/yoursite">
    Options FollowSymLinks
    AllowOverride All
</Directory>

I needed AllowOverride All to recognize the .htaccess file.

Edit

I also needed to add the path to the site root in the directory tag itself. i.e. <Directory "C:/Websites/htdocs/yoursite">. This was the default in the samples I used.


To get this working, I added the following to /etc/apache2/httpd.conf (which is a zero-length file by default when Apache is installed) and then restarted Apache. Now Options -Indexes in the .htaccess file works as desired. Here is the bare minimum required to get it to work:

/etc/apache2/httpd.conf :

<VirtualHost *:80>
        DocumentRoot /var/www
        <Directory / >
        </Directory>
</VirtualHost>

lanzz's suggestion to add a line of gibberish to the .htaccess file to see if it was being read was helpful in diagnosing the problem.

Note that AllowOveride defaults to All, per Evan Mulawski's comment, so it's not required in the minimal set of httpd.conf lines above.


You should check that the Apache config allows for the .htaccess to be executed. In your virtualhost config, there should be a line:

AllowOverride All

If there isn't, that's why the .htaccess isn't taking effect.


As there's no httpd.conf file anymore, what you need to do on a VPS is:

  1. Go to /etc/apache2/sites-enabled/
  2. Do ls to find the file for the website you're looking for
  3. Edit the corresponding file with nano THE_CONF_FILE or with whatever editor you'd like
  4. Change all AllowOverride None values that you see in different <Directory> ... </Directory>s to AllowOverride All
  5. Save the file and close it

  6. Now you need to enable module rewrite by running the command:sudo a2enmod rewrite

  7. And finally to activate the new configuration, you need to run: service apache2 restart

It'll work like a charm now!