在本地开发服务器上,我有一个像这样的网站的Apache conf
<VirtualHost *:80> ServerAdmin no-reply@localhost ServerName sandbox.mysite.internal DocumentRoot /var/www/vhosts/sandbox/mysite ErrorLog logs/sandbox/mysite-error.log CustomLog logs/sandbox/mysite-access.log common </VirtualHost>
如果我访问以下地址(没有index.php或index.html)
http://sandbox.mysite.internal
我得到了Apache CentOStesting页面
如果我访问像一个子目录
http://sandbox.mysite.internal/test/
我得到一个403 Forbidden错误。 所以我在这里添加下面的.htaccess :
/var/www/vhosts/sandbox/mysite/test/.htaccess
内容:
Options +Indexes
现在,当我访问:
http://sandbox.mysite.internal/test/
我仍然得到403禁止。
我如何使目录索引显示?
我一直认为.htaccess指令覆盖任何httpd.conf指令。 但是我错了吗? 在我的httpd.conf有一些设置,使我的.htaccess指令被忽略?
当然, AllowOverride None会阻止.htaccess文件运行。 但是,为什么要使用它们呢? Apache的build议是不要使用.htaccess除非你无法访问主configuration。
试试这个,而是:
<VirtualHost *:80> ServerAdmin no-reply@localhost ServerName sandbox.mysite.internal DocumentRoot /var/www/vhosts/sandbox/mysite ErrorLog logs/sandbox/mysite-error.log CustomLog logs/sandbox/mysite-access.log common <Directory /var/www/vhosts/sandbox/mysite/test/> Order allow,deny Allow from all Options +Indexes </Directory> </VirtualHost>
如果这不起作用,请查看Apache的错误日志; 例如,您的文件/目录权限可能有问题。