如何限制对我的zend framework 2公用文件夹的访问,例如css
文件夹?我想隐藏当我通过http
访问文件夹时显示的目录列表。但我希望应用程序可以正确使用这些文件。
当我访问我的域上的css
文件夹时,会显示此目录列表:
虚拟主机配置:
<VirtualHost *:80>
ServerName server1.jobsoft.co
ServerAlias server1.jobsoft.co
DocumentRoot /var/www/html/engsvc_dev/public
ErrorLog /var/log/httpd/engsvc_dev.error.log
CustomLog /var/log/httpd/engsvc_dev.common.log common
<Directory /var/www/html/engsvc_dev/public>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
我的.htaccess
文件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?server1.jobsoft.co$
RewriteCond %{REQUEST_URI} !^/engsvc_dev/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1
RewriteCond %{HTTP_HOST} ^(www.)?server1.jobsoft.co$
RewriteRule ^(/)?$ /public/index.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
答案 0 :(得分:2)
我编辑了您的问题并添加了术语&#34;目录列表&#34;因为这是通常调用屏幕上显示的文件列表的方式。起初,在阅读完问题后,我并不知道你想要什么。但是在你的评论之后我得到了它。
通常,您可以通过向Apache服务器的.htaccess
文件添加其他规则来阻止目录列表。
您可以找到很多关于如何执行此操作的帖子,例如here和here或更多by searching the topic on stackoverflow。
魔术被关闭:
Options -Indexes
然后开启
Options +Indexes
在this apache documentation中,您可以阅读选项指令一章中的以下内容:
<强>索引强> 如果请求映射到目录的URL并且该目录中没有
DirectoryIndex
(例如,index.html
),则mod_autoindex
将返回该目录的格式化列表。