【问题标题】:Usage of both "Order Deny,Allow" and "RewriteRule"“Order Deny,Allow”和“RewriteRule”的用法
【发布时间】:2020-09-27 11:49:36
【问题描述】:

我已阅读 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]

但问题仍然存在。

【问题讨论】:

  • 确认您的 Apache 版本?你可以使用&lt;Files test.txt&gt; Order allow, deny Deny from all &lt;/ Files&gt;
  • @Pandurang 我想从一个独特的/.htaccess 做所有事情,而不是像这样的每个子目录中的 htaccess:/articles/.htaccess 等。
  • @Pandurang 我尝试过类似的事情(请参阅几秒钟前的最后一次编辑),但它不起作用(可能是因为RewriteRule / &lt;Files&gt; 混合?)
  • 为了测试,目的是禁用其他重写规则。也可以试试RewriteRule ^/?/articles/$ - [F,L]

标签: apache .htaccess


【解决方案1】:

尝试使用以下重写规则。

RewriteRule articles/.*$ - [F]

这使用F|forbidden 标志。

注意:

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

【讨论】:

    猜你喜欢
    • 2017-03-15
    • 1970-01-01
    • 2011-01-16
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 2017-07-29
    • 1970-01-01
    相关资源
    最近更新 更多