I created an .htaccess file with only the following line:
我创建了一个只包含以下行的.htaccess文件:
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).
我刚刚安装了Apache2并使用了所有默认设置(我没有修改apache2.conf或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
操作系统:Ubuntu 12.04(精确穿山甲)Apache2版本:服务器版本:Apache / 2.2.22(Ubuntu)服务器内置:2012年2月13日01:51:56
$ ls -l .htaccess
-rwxr-xr-x .htaccess$ 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.
我接受了lanzz的建议,并在.htaccess文件中添加了乱码,并发现.htaccess文件没有被读取。
7 个解决方案
#1
36
You should check that the Apache config allows for the .htaccess to be executed. In your virtualhost config, there should be a line:
您应该检查Apache配置是否允许执行.htaccess。在您的virtualhost配置中,应该有一行:
AllowOverride All
AllowOverride All
If there isn't, that's why the .htaccess isn't taking effect.
如果没有,那就是.htaccess没有生效的原因。
#2
27
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(安装Apache时默认为零长度文件),然后重新启动Apache。现在,选项 - .htaccess文件中的索引可以根据需要运行。以下是使其工作所需的最低要求:
/etc/apache2/httpd.conf :
/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.
lanzz建议在.htaccess文件中添加一行乱码来查看它是否被读取有助于诊断问题。
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.
请注意,根据Evan Mulawski的评论,AllowOveride默认为All,因此在上面的最小httpd.conf行中不需要它。
#3
16
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
我有同样的问题。我使用的是虚拟主机,所以我修改了httpd-vhosts.conf,所以如果你使用的话,这可能有所帮助
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.
我需要AllowOverride All来识别.htaccess文件。
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.
我还需要在目录标记本身中添加站点根目录的路径。即 <目录“c: websites htdocs yoursite”> 。这是我使用的样本中的默认值。
#4
7
As there's no httpd.conf
file anymore, what you need to do on a VPS is:
由于没有httpd.conf文件,您需要在VPS上执行的操作是:
- Go to
/etc/apache2/sites-enabled/
- 转至/ etc / apache2 / sites-enabled /
- Do
ls
to find the file for the website you're looking for - 请找到您正在寻找的网站的文件
- Edit the corresponding file with
nano THE_CONF_FILE
or with whatever editor you'd like - 使用nano THE_CONF_FILE或您想要的任何编辑器编辑相应的文件
- Change all
AllowOverride None
values that you see in different<Directory> ... </Directory>
s toAllowOverride All
-
将您在不同
... 中看到的所有AllowOverride None值更改为AllowOverride All -
Save the file and close it
保存文件并关闭它
-
Now you need to enable module rewrite by running the command:
sudo a2enmod rewrite
现在,您需要通过运行命令启用模块重写:sudo a2enmod rewrite
- And finally to activate the new configuration, you need to run:
service apache2 restart
- 最后要激活新配置,需要运行:service apache2 restart
It'll work like a charm now!
它现在就像魅力一样!
#5
4
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
在httpd.conf或/etc/apache2/sites-available/...conf中的默认虚拟主机文件中
#6
3
I solved this problem on RHEL by editing file /etc/http/conf/httpd.conf
I changed all
我通过编辑文件/etc/http/conf/httpd.conf在RHEL上解决了这个问题我改变了所有
AllowOverride None
To
至
AllowOverride All
Also you can check httpd.conf AllowOverride by following command on RHEL
您还可以通过RHEL上的以下命令检查httpd.conf AllowOverride
grep -i AllowOverride /etc/conf/conf/httpd.conf
#7
1
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:
此外,除了将AllowOverride All更改为vhost配置文件之外,您可能还需要在.htaccess文件的开头添加以下内容:
RewriteEngine On
RewriteBase /
Otherwise may still not detecting the rewrites or redirects.
否则可能仍未检测到重写或重定向。
#1
36
You should check that the Apache config allows for the .htaccess to be executed. In your virtualhost config, there should be a line:
您应该检查Apache配置是否允许执行.htaccess。在您的virtualhost配置中,应该有一行:
AllowOverride All
AllowOverride All
If there isn't, that's why the .htaccess isn't taking effect.
如果没有,那就是.htaccess没有生效的原因。
#2
27
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(安装Apache时默认为零长度文件),然后重新启动Apache。现在,选项 - .htaccess文件中的索引可以根据需要运行。以下是使其工作所需的最低要求:
/etc/apache2/httpd.conf :
/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.
lanzz建议在.htaccess文件中添加一行乱码来查看它是否被读取有助于诊断问题。
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.
请注意,根据Evan Mulawski的评论,AllowOveride默认为All,因此在上面的最小httpd.conf行中不需要它。
#3
16
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
我有同样的问题。我使用的是虚拟主机,所以我修改了httpd-vhosts.conf,所以如果你使用的话,这可能有所帮助
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.
我需要AllowOverride All来识别.htaccess文件。
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.
我还需要在目录标记本身中添加站点根目录的路径。即 <目录“c: websites htdocs yoursite”> 。这是我使用的样本中的默认值。
#4
7
As there's no httpd.conf
file anymore, what you need to do on a VPS is:
由于没有httpd.conf文件,您需要在VPS上执行的操作是:
- Go to
/etc/apache2/sites-enabled/
- 转至/ etc / apache2 / sites-enabled /
- Do
ls
to find the file for the website you're looking for - 请找到您正在寻找的网站的文件
- Edit the corresponding file with
nano THE_CONF_FILE
or with whatever editor you'd like - 使用nano THE_CONF_FILE或您想要的任何编辑器编辑相应的文件
- Change all
AllowOverride None
values that you see in different<Directory> ... </Directory>
s toAllowOverride All
-
将您在不同
... 中看到的所有AllowOverride None值更改为AllowOverride All -
Save the file and close it
保存文件并关闭它
-
Now you need to enable module rewrite by running the command:
sudo a2enmod rewrite
现在,您需要通过运行命令启用模块重写:sudo a2enmod rewrite
- And finally to activate the new configuration, you need to run:
service apache2 restart
- 最后要激活新配置,需要运行:service apache2 restart
It'll work like a charm now!
它现在就像魅力一样!
#5
4
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
在httpd.conf或/etc/apache2/sites-available/...conf中的默认虚拟主机文件中
#6
3
I solved this problem on RHEL by editing file /etc/http/conf/httpd.conf
I changed all
我通过编辑文件/etc/http/conf/httpd.conf在RHEL上解决了这个问题我改变了所有
AllowOverride None
To
至
AllowOverride All
Also you can check httpd.conf AllowOverride by following command on RHEL
您还可以通过RHEL上的以下命令检查httpd.conf AllowOverride
grep -i AllowOverride /etc/conf/conf/httpd.conf
#7
1
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:
此外,除了将AllowOverride All更改为vhost配置文件之外,您可能还需要在.htaccess文件的开头添加以下内容:
RewriteEngine On
RewriteBase /
Otherwise may still not detecting the rewrites or redirects.
否则可能仍未检测到重写或重定向。