[英]Deny access to subfolders and files using .htaccess
I have the following directory structure 我有以下目录结构
localhost_foler
|__test
|
|__d1/
| |__f1.html
|
|__d2/
|
|__d3/
|
|__d4/
|
|__.htaccess
What I want to achieve is to deny access to all files in d2
, d3
and d4
but allow them to be included by php files. 我想要实现的是拒绝访问d2
, d3
和d4
所有文件,但允许它们被php文件包含。 Also for d1
, excluding the file f1.html
the rest needs to be blocked. 同样对于d1
,不包括文件f1.html
,其余部分需要被阻止。
Requirement : Only a single .htaccess
file in the test
dir. 要求 :只有单一 .htaccess
在文件test
目录。
What I tried: 我尝试了什么:
Options -Indexes
<Files "d1/*">
Deny From All
</Files>
<FilesMatch "^f1\.html">
Allow from all
</FilesMatch>
<Files "d2/*">
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
</Files>
<Files "d3/*">
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
</Files>
<Files "d4/*">
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
</Files>
You can use the following rewriteRule to forbid access to files inside the folders : 您可以使用以下rewriteRule禁止访问文件夹中的文件:
RewriteEngine on
RewriteCond %{THE_REQUEST} !/d1/f1\.html [NC]
RewriteCond %{THE_REQUEST} /(d1|d2|d3|d4)/.+ [NC]
RewriteRule ^ - [R=403,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.