2015-03-31 129 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