2015-03-31 174 views
1

嗨我寫一個Codeigniter應用程序,我創建一些目錄,因爲我上傳文件。htaccess限制訪問文件夾和子文件夾

如何在我的.htaccss文件中添加一條規則,該規則禁止直接訪問我的上傳文件夾及其子文件夾,同時允許訪問這些文件夾中的文件?

我的文件結構如下

index.html 
.htaccess 
uploads/ <- No direct access allowed 
uploads/gallery/ <- No direct access allowed 
uploads/gallery/1 <- No direct access allowed 
uploads/gallery/1/file1.jpg <- access is ok 
uploads/gallery/1/file2.jpg <- access is ok 
uploads/gallery/2 <- No direct access allowed 
uploads/gallery/2/file3.jpg <- access is ok 
uploads/gallery/2/file4.jpg <- access is ok 

回答

3

創建一個文件/uploads/.htaccess,並有這樣的代碼:

Options -Indexes 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^- [F] 
+1

謝謝:)得上的.htaccess規則 – Oldenborg 2015-04-01 07:55:04

+1

讀了http://askapache.com是相當不錯的資源 – anubhava 2015-04-01 08:03:08