2017-01-26 54 views
3

如何限制访问我的zend框架2公用文件夹,例如css文件夹?我想隐藏当我通过http访问文件夹时出现的目录列表。但我希望这些文件可以被应用程序正确使用。访问浏览器中的公共文件夹时隐藏目录列表

这个目录列表显示出来,当我访问我的域名的css文件夹:

enter image description here

虚拟主机配置:

<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

'css'文件通常需要公开访问。你是什​​么意思*“由应用程序正确使用”*。如果您的意思是在您的客户端应用程序/代码中使用它,那么它需要公开访问。如果你的意思是你想在你的服务器端代码中使用它,那么我建议你从公用文件夹中删除这个文件。 – Wilt

+0

我不想在浏览器上显示结构,或者是不可能的? –

+0

检查[这里](https://www.thesitewizard.com/apache/prevent-directory-listing-htaccess.shtml)或[这里](http://stackoverflow.com/questions/2530372/how-do-i -disable-目录浏览) – Wilt

回答

2

我编辑了你的问题,并添加了术语“目录列表”,因为这是你的屏幕上显示的文件列表通常被称为。起初,在阅读你的问题后,我不知道你想要什么。但在你的评论后,我明白了。

通常情况下,您可以通过向您的Apache服务器的.htaccess文件添加额外的规则来阻止目录列表。

你可以找到很多关于如何做到这一点的帖子,例如herehere或更多by searching the topic on stackoverflow

神奇的是通过关闭:

Options -Indexes 

而且通过

Options +Indexes 

开启在this apache documentation可以读取章节选项指令在以下几点:

索引 如果请求映射到目录的URL,并且该目录中没有DirectoryIndex(例如,index.html),则mod_autoindex将返回目录的格式化列表。

相关问题