如何拒绝访问在.htaccess文件 [英] How to deny access to a file in .htaccess

查看:430
本文介绍了如何拒绝访问在.htaccess文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下.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]

这篇关于如何拒绝访问在.htaccess文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆