【问题标题】:How to protect ASSETS FOLDER in codeigniter如何在 codeigniter 中保护资产文件夹
【发布时间】:2017-07-26 06:29:14
【问题描述】:
我只想在客户端保护我的资产文件夹。我所有的文件都可以公开访问。我想保护它。我有如下规则.htaccess,那里有错误的规则吗?
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
【问题讨论】:
标签:
php
.htaccess
codeigniter
mod-rewrite
【解决方案1】:
你可以做两件事
- 通过
.htaccess(未测试)
- 通过
index.html
1。 .htaccess
在资产文件夹中添加.htaccess
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
2。 index.html
在目录中创建index.html文件并添加这个
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
输出
当有人在外面访问时,你会在浏览器上看到这个
禁止访问目录。
【解决方案2】:
创建一个助手来访问这些“资产”。并且只允许从您的服务器对这些文件的请求。这是解决这个问题的一种方法。
【解决方案3】:
您可以保护您的assets 或文件夹,就像CI 保护其应用程序文件一样。
只需从应用程序中复制 .htaccess 文件和 index.html 文件并将其粘贴到您的资产文件中。