简体   繁体   English

如何使用一个.htaccess拒绝访问多个文件夹?

[英]How to deny access to multiple folders using one .htaccess?

I have multiple folders on my website and one .htaccess in the root of the site. 我的网站上有多个文件夹,网站根目录中有一个.htaccess I want to deny access to some of them using htaccess . 我想使用htaccess拒绝访问其中的一些。 I found this post: 我发现了这篇文章:

Deny access to one specific folder in .htaccess 拒绝访问.htaccess中的一个特定文件夹

Its solution is creating .htaccess file in target folder but I want to do this work using one .htaccess . 它的解决方案是在目标文件夹中创建.htaccess文件,但我想使用一个.htaccess来完成这项工作。 I want to deny access to target folders using one .htaccess in the root of the site. 我想使用网站根目录中的一个.htaccess拒绝对目标文件夹的访问。

Is it possible? 可能吗?

If you want to deny access to subfolders from root lavel htaccess, you can use the following RewriteRules : 如果要拒绝从根目录htaccess访问子文件夹,可以使用以下RewriteRules:

RewriteRule ^folderA/$ - [R=403,L]
RewriteRule ^folderB/$ - [R=403,L]

The rules will return a 403 forbidden error if /folderA/ and /folderB is requested. 如果请求/ folderA /和/ folderB,则规则将返回403禁止的错误。

You can try: 你可以试试:

RewriteEngine On
RewriteRule ^folder1/ - [F]
RewriteRule ^someotherfolder/ - [F]
# you can also use RegEx:
RewriteRule ^folder([0-9]+)/ - [F]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM