Reputation: 28152
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.
Upvotes: 42
Views: 84849
Reputation: 19
One more reason one's htaccess file is not being read is an existing htaccess enforces a HTTPS 301 redirect that the browser then caches which can be a problem if virtual hosts are not configured correctly. Full explanation below.
If one is setting up a virtual host in Apache and XAMPP for example, the first time you fire up the URL of your virtual host, if you have an existing htaccess file with a HTTPS 301 redirect, your browser will get redirected to the HTTPS version of your virtual host. But there's a potential problem. If you haven't explicitly set up a *:433 virtual host for the domain in question, in your Apache vhosts config file, Apache will default to using the first virtual host listed.
Depending on the contents of this default virtual host it may be impossible to distinguish what is happening, and user will maddeningly try to determine why changes to the htaccess file are no longer being processed.
Once you determine what is happening, the workaround is to disable any HTTPS redirects and reboot and try again without HTTPS. The real solution is to complete a full virtual host 443 setup with certificate.
Upvotes: 1
Reputation: 2213
I solved this problem on RHEL by editing file /etc/http/conf/httpd.conf
I changed all
AllowOverride None
To
AllowOverride All
Also you can check httpd.conf AllowOverride by following command on RHEL
grep -i AllowOverride /etc/conf/conf/httpd.conf
Upvotes: 3
Reputation: 21
Also, beside changing AllowOverride All to the vhost configuration file, you may also need to add the following at the beginning of the .htaccess file:
RewriteEngine On
RewriteBase /
Otherwise may still not detecting the rewrites or redirects.
Upvotes: 1
Reputation: 3653
As there's no httpd.conf
file anymore, what you need to do on a VPS is:
/etc/apache2/sites-enabled/
ls
to find the file for the website you're looking fornano THE_CONF_FILE
or with whatever editor you'd likeAllowOverride None
values that you see in different <Directory> ... </Directory>
s to AllowOverride All
Save the file and close it
Now you need to enable module rewrite by running the command:sudo a2enmod rewrite
service apache2 restart
It'll work like a charm now!
Upvotes: 12
Reputation: 321
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.
Upvotes: 16
Reputation: 4285
In case you have
AllowOverride None
Change that to:
AllowOverride All
in your httpd.conf or in your default virtualhost file in in /etc/apache2/sites-available/...conf
Upvotes: 5
Reputation: 28152
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.
Upvotes: 30
Reputation: 12010
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.
Upvotes: 61