繁体   English   中英

在浏览器中访问公用文件夹时隐藏目录列表

[英]Hide directory listing when accessing public folders in the browser

如何限制访问我的zend框架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>

我编辑了您的问题并添加了术语“目录列表”,因为这是通常调用屏幕上显示的文件列表的方式。 起初我在阅读你的问题后并不知道你想要什么。 但是在你的评论之后我得到了它。

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

您可以在stackoverflow上搜索主题,找到有关如何执行此操作的大量帖子,例如此处此处或更多内容

魔术被关闭:

Options -Indexes

然后转过来

Options +Indexes

此apache文档中,您可以阅读选项指令一章中的以下内容:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM