我创建了一个仅包含以下行的.htaccess文件:
选项 - 索引
但是,仍会显示该目录的索引.
我刚刚安装了Apache2并使用了所有默认设置(我没有修改apache2.conf或httpd.conf).
操作系统:Ubuntu 12.04 (Precise Pangolin)
Apache2版本:Server version: Apache/2.2.22 (Ubuntu) Server built: Feb 13 2012 01:51:56
$ ls -l .htaccess
-rwxr-xr-x .htaccess
编辑:
我接受了lanzz的建议并在.htaccess文件中添加了乱码,并发现该.htaccess文件未被读取.
Chr*_*nry 47
您应该检查Apache配置是否允许执行.htaccess.在您的virtualhost配置中,应该有一行:
AllowOverride All
如果没有,那就是.htaccess没有生效的原因.
Rob*_*ark 27
为了实现这一点,我添加了以下内容/etc/apache2/httpd.conf(安装Apache时默认为零长度文件),然后重新启动Apache.现在Options -Indexes在.htaccess文件中按预期工作.以下是使其工作所需的最低要求:
/etc/apache2/httpd.conf :
<VirtualHost *:80>
DocumentRoot /var/www
<Directory / >
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
lanzz建议在.htaccess文件中添加一行乱码以查看是否正在读取该文件有助于诊断问题.
请注意,AllowOveride默认情况下All,根据Evan Mulawski的评论,所以在httpd.conf上面的最小线条中不需要它.
Iss*_*ssa 16
我有同样的问题.我使用的是虚拟主机,所以我修改了httpd-vhosts.conf,所以如果你使用的话,这可能有所帮助
在配置主机的位置引用目录标记与文档根目录相同
<VirtualHost *:8080>
ServerName somelocalserver
DocumentRoot "C:/Websites/htdocs/yoursite"
<Directory "C:/Websites/htdocs/yoursite">
Options FollowSymLinks
AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)
我需要AllowOverride All识别.htaccess文件.
编辑
我还需要在目录标记本身中添加站点根目录的路径.即<Directory "C:/Websites/htdocs/yoursite">.这是我使用的样本中的默认值.
由于没有httpd.conf文件,您需要在VPS上执行的操作是:
/etc/apache2/sites-enabled/ls找到你要找的网站上的文件nano THE_CONF_FILE或使用您想要的任何编辑器编辑相应的文件AllowOverride None将您在不同<Directory> ... </Directory>s中看到的所有值更改为AllowOverride All保存文件并关闭它
现在,您需要通过运行命令启用模块重写:sudo a2enmod rewrite
service apache2 restart它现在就像一个魅力!
如果你有
AllowOverride None
Run Code Online (Sandbox Code Playgroud)
改为:
AllowOverride All
Run Code Online (Sandbox Code Playgroud)
在httpd.conf或/etc/apache2/sites-available/...conf中的默认虚拟主机文件中
| 归档时间: |
|
| 查看次数: |
66714 次 |
| 最近记录: |