htaccess 通过 ip 范围访问文件 [英] htaccess access to file by ip range

查看:28
本文介绍了htaccess 通过 ip 范围访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅允许具有某个 ip 地址范围内的 ip 的用户访问文件?

How to allow access to file only to users with ip which are in a range of ip addresses?

例如文件 admin.php.范围从 0.0.0.0 到 1.2.3.4.

For example file admin.php. and range from 0.0.0.0 to 1.2.3.4.

我只需要配置访问一个文件而不是目录.

I need configure access to only ONE file not to directory.

推荐答案

只需添加一个 FilesMatchFiles 指令来限制到特定的脚本.

Just add a FilesMatch or Files directive to limit it to a specific script.

以下内容将阻止访问所有以admin.php"结尾的脚本:

The following would block acces to all scripts ending in "admin.php" :

<FilesMatch "admin.php$">
    Order deny,allow
    Deny from all
    Allow from 10.0.0.0/24
</FilesMatch>

以下内容只会阻止 admin.php :

The following would ONLY block admin.php :

<Files "admin.php">
    Order deny,allow
    Deny from all
    Allow from 10.0.0.0/24
</Files>

有关详细信息,请参阅 配置部分 上的 apache 文档.

For more information refer to the apache docs on Configuration Sections.

这篇关于htaccess 通过 ip 范围访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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