I created an .htaccess file with only the following line:
Options -Indexes
However, the index is still shown for the directory.
I just installed Apache2 and am using all the defaults (I did not modify apache2.conf or httpd.conf).
OS: Ubuntu 12.04 (Precise Pangolin)
Apache2 version: Server version: Apache/2.2.22 (Ubuntu) Server built: Feb 13 2012 01:51:56
$ ls -l .htaccess
-rwxr-xr-x .htaccess
EDIT:
I took lanzz's advice and added gibberish to the .htaccess
file, and discovered that the .htaccess
file is not being read.
Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.
The Indexes option sets whether you can "browse" the directory or not. If indexes is set to plus, and the directory has no index. html or index. php (of whatever) file, it will show the contents of the directory just like your filemanager would do.
htaccess file is a powerful website file that controls high-level configuration of your website. On servers that run Apache (a web server software), the . htaccess file allows you to make changes to your website's configuration without having to edit server configuration files.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With