简体   繁体   中英

Hide directory listing when accessing public folders in the browser

How can I restrict access to my zend framework 2 public folder for example the css folder? I would like to hide the directory listing that shows up when I access a folder via http . But I want that the files can be utilized properly by the application.

This directory list shows up when I access the css folder on my domain:

在此输入图像描述

Virtual Host Config:

<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>

My .htaccess file:

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>

I edited your question and added the term "directory listing" because this is how this list of files that shows on your screen is commonly called. At first I didn't know what you wanted after reading your question. But after your comment I got it.

Normally you can prevent directory-listing by adding an additional rule to your the .htaccess file for your Apache server.

You can find lots of posts on how to do this, for example here and here or many more by searching the topic on stackoverflow .

The magic is turned off by:

Options -Indexes

And turned on by

Options +Indexes

In this apache documentation you can read the following in the chapter Options Directive :

Indexes If a URL which maps to a directory is requested and there is no DirectoryIndex (eg, index.html ) in that directory, then mod_autoindex will return a formatted listing of the directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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