【问题标题】:How to prevent direct access to the files with CodeIgniter如何防止使用 CodeIgniter 直接访问文件
【发布时间】:2020-04-14 06:40:08
【问题描述】:

如何防止直接访问应用程序中的文件夹/文件等文件?

我在应用程序文件夹中看到的文件 .htaccess 和 index.html 包括:

.htaccess

<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
 Deny from all
</IfModule>

index.html

<!DOCTYPE html>
<html>
<head>
    <title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
</html>

我在根项目目录中创建一个新文件夹,名称为:Customers where will be stored customers PDF files。我将两个文件 .htaccess 和 index.html 从应用程序粘贴到客户,但 PDF 文件仍然能够直接访问。

如何让它们像应用程序文件夹文件一样只能访问系统?

【问题讨论】:

  • 你可以在这里找到一个很好的答案stackoverflow.com/questions/37981011/…
  • @sintakonte 这是如何分离系统和应用程序文件夹,我正在寻找如何创建只有 codeigniter 系统才能访问里面的文件的新文件夹
  • 以这种方式思考 - 如果您以这种方式设置 apache vhost - 应用程序文件夹位于公共根目录之外 - 因此您可以在应用程序目录中创建一个文件夹,例如application/uploads/customers 由于您的设置更安全而自动受到保护
  • @sintakonte 我的帐户是有限的,不像所有者帐户,我没有访问当前项目文件夹之外的权限。
  • @sintakonte 有没有办法拒绝所有未登录用户访问特殊文件夹/文件?

标签: php .htaccess codeigniter


【解决方案1】:

了解这种方式的工作原理。

在客户文件夹中,我将 .htaccess 像这样(将域替换为您的),将阻止直接访问文件,但允许从系统访问

RewriteCond %{REQUEST_FILENAME} ^.*(pdf|)$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain\.com/ [NC]
RewriteRule . - [R=403,L]

【讨论】:

    【解决方案2】:

    最佳做法是将它们存储在您的公用文件夹之外。

    要请求这些文件,您可以使用另一个主题中给出的答案: how to access documents(.pdf .doc etc) which are stored outside of the root folder

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多