I created an .htaccess file with only the following line:
Options -Indexes
However, the index is still shown for the directory.<
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.
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.
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.
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.
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.
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