您好我正在编写Codeigniter应用程序,我在上传文件时创建了一些目录。
如何向我的.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
答案 0 :(得分:3)
创建一个文件/uploads/.htaccess
并拥有以下代码:
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ - [F]