“拒绝订单,允许”和“重写规则”的用法

时间:2020-06-08 13:34:17

标签: apache .htaccess

我已经阅读了Deny from all in subdirectory htaccess not overriding file rules in root htaccesshtaccess "order" Deny, Allow, Deny,但是我不明白为什么这行不通:

Order Deny,Allow
<Files articles/*.*>
Deny from all
</Files>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

文件example.com/articles/test.txt仍然可见,但不能查看。这表明articles/*.*规则不起作用。

我的.htaccess哪里出问题了?


注意:由于我使用的是Apache 2.4,因此我尝试过:

<Files "articles/*.*">
Require all denied
</Files>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

但是问题仍然存在。

1 个答案:

答案 0 :(得分:1)

尝试使用以下重写规则。

RewriteRule articles/.*$ - [F]

这使用F|forbidden标志。

注意:

使用[F]时,隐含一个[L]-即立即返回响应,并且不评估其他规则。