php - 有没有办法只允许访问以前在 .htaccess 中列出的文件?

标签 php apache .htaccess http server

我需要服务器只允许访问三个文件(index.phpestilo.cssscripts.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/

相关文章:

php - laravel 如何路由到 javascript 上的路由?

php - xampp 开发 : creating project(folders and files) in htdocs folder

php - 帮助解决奇怪的 PHP javascript/hidden iframe hack

python - Apache 不提供 django 管理静态文件

.htaccess - 请求的 404 之前的 header 代码 302

php - 在 php 中创建包含用户名的用户友好 url

php - CURL: SSL 证书失败,验证 CA 证书是否正常

php - 如何在 codeigniter 中获取当前日期

PHP echo 里面的 echo

Apache(不是浏览器)正在缓存我的文件