Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 570
Rob Bednark Avatar asked May 26 '12 21:05

Rob Bednark


People also ask

Why is my .htaccess file not working?

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.

What does the .htaccess command options indexes do?

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.

How do I read .htaccess file?

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.


2 Answers

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.

like image 198
Chris Henry Avatar answered Oct 01 '22 19:10

Chris Henry


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.

like image 44
Rob Bednark Avatar answered Oct 01 '22 19:10

Rob Bednark