Codeigniter .htaccess:授予对所有文件的公共访问权限,但不能授予文件夹的公共访问权限


Codeigniter .htaccess: Give public access to all files but not the folder

我的文件格式像

  application
       - controllers
       - views etc...
  assetes
       - Images
       - Css etc...

和我的.htaccess文件如下:

#Deny from all
RewriteEngine on
RewriteCond $1 !^(index'.php|assets|robots'.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
我的问题是资产文件夹访问每个用户

查看所有图像和所有css文件,但需要的只是用户访问资产文件夹文件而不是访问整个文件夹

请帮助我谢谢!

只需

index.html文件放入要阻止目录访问的文件夹中即可完成阻止目录访问。

这是标准CodeIgniter安装的方式。下面的索引.html文件可以在application'controllers文件夹中找到。

<html>
<head>
    <title>403 Forbidden</title>
</head>
<body>
    <p>Directory access is forbidden.</p>
</body>
</html>

htaccess 中使用以下行RewriteCond %{REQUEST_FILENAME} !-f这是用于文件访问

RewriteCond %{REQUEST_FILENAME} !-d这是针对字典访问