我需要服务器只允许访问三个文件(index.php
、estilo.css
和 scripts.js
),以及拒绝访问目录中的任何其他文件类型。
我认为最简单的方法是通过 .htaccess
。但如果有另一种方式...
最佳答案
在 .htaccess
中,您可以拒绝访问所有文件,然后专门允许访问这三个文件。但是,具体如何执行此操作取决于您使用的是 Apache 2.4+ 还是早期版本的 Apache。
在 Apache 2.4+ 上
Require all denied
<FilesMatch "^(index\.php|estilo\.css|scripts\.js)$">
Require all granted
</FilesMatch>
在 Apache 2.2 上
Order Deny,Allow
Deny from all
<FilesMatch "^(index\.php|estilo\.css|scripts\.js)$">
Allow from all
</FilesMatch>
关于php - 有没有办法只允许访问以前在 .htaccess 中列出的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44292762/