Reputation: 411
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>
Upvotes: 3
Views: 2501
Reputation: 44383
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
(e.g.,index.html
) in that directory, thenmod_autoindex
will return a formatted listing of the directory.
Upvotes: 2