如何拒绝访问在.htaccess文件文件、htaccess

2023-09-02 09:36:18 作者:姐是限量版╮你爱要不要

我有以下.htaccess文件:

I have the following .htaccess file:

RewriteEngine On
RewriteBase /

# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>

# Protect log.txt
<Files ./inscription/log.txt>
Order Allow,Deny
Deny from all
</Files>

# Disable directory browsing
Options All -Indexes

我试图禁止游客进入下列文件:

I am trying to forbid visitors to access the following file:

domain.com/inscription/log.txt

但上面我所不能正常工作。我仍然可以从浏览器远程访问文件

but what I have above does not work: I can still access the file from the browser remotely.

推荐答案

在一个htaccess文件,在&LT的范围;文件&GT; 指令只适用于该目录(我想,以避免混淆,当规则/子目录的htaccess的指令得到应用并取代那些从父)。

Within an htaccess file, the scope of the <Files> directive only applies to that directory (I guess to avoid confusion when rules/directives in the htaccess of subdirectories get applied superceding ones from the parent).

所以,你可以有:

<Files "log.txt">
Order Allow,Deny
Deny from all
</Files>

在你的题词目录中的htaccess文件。或者你也可以使用mod_rewrite的排序来处理这两种情况下拒绝访问htaccess文件,以及log.txt的:

In an htaccess file in your inscription directory. Or you can use mod_rewrite to sort of handle both cases deny access to htaccess file as well as log.txt:

RewriteRule /?.htaccess$ - [F,L]

RewriteRule ^/?inscription/log.txt$ - [F,L]