2017-01-26 53 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將返回目錄的格式化列表。

相關問題