我只是想保护客户端中的 Assets 文件夹。我的所有文件都可以公开访问。我想保护它。我有如下规则 .htaccess
,有什么错误的规则吗?
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
最佳答案
你可以做两件事
- 通过
.htaccess
(未测试) - 通过
index.html
1。 .htaccess
在 Assets 文件夹中添加.htaccess
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
2。索引.html
在目录中创建index.html
文件并添加此
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
输出
当有人从外部访问时,您会在浏览器上看到此内容
Directory access is forbidden.
关于php - 如何保护 codeigniter 中的 Assets 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45319082/