php htaccess 通过 ip 范围访问文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5042399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
htaccess access to file by ip range
提问by Mirgorod
How to allow access to file only to users with ip which are in a range of ip addresses?
如何仅允许具有 ip 地址范围内的 ip 的用户访问文件?
For example file admin.php. and range from 0.0.0.0 to 1.2.3.4.
例如文件 admin.php。范围从 0.0.0.0 到 1.2.3.4。
I need configure access to only ONE file not to directory.
我只需要配置对一个文件而不是目录的访问权限。
回答by wimvds
Just add a FilesMatchor Filesdirective to limit it to a specific script.
只需添加FilesMatch或Files指令以将其限制为特定脚本。
The following would block acces to all scripts ending in "admin.php" :
以下内容将阻止访问所有以 "admin.php" 结尾的脚本:
<FilesMatch "admin\.php$">
Order deny,allow
Deny from all
Allow from 10.0.0.0/24
</FilesMatch>
The following would ONLY block admin.php :
以下只会阻止 admin.php :
<Files "admin.php">
Order deny,allow
Deny from all
Allow from 10.0.0.0/24
</Files>
For more information refer to the apache docs on Configuration Sections.
有关更多信息,请参阅配置部分上的 apache 文档。
回答by Pascal Qyy
check the man page of the Allow Directive
检查允许指令的手册页
Order Deny,Allow
Deny from all
Allow from 10.1.0.0/255.255.0.0
A partial IP address
部分 IP 地址
Example:
例子:
Allow from 10.1
Allow from 10 172.20 192.168.2
The first 1 to 3 bytes of an IP address, for subnet restriction.
IP 地址的前 1 到 3 个字节,用于子网限制。
A network/netmask pair
网络/网络掩码对
Example:
例子:
Allow from 10.1.0.0/255.255.0.0
A network a.b.c.d, and a netmask w.x.y.z. For more fine-grained subnet restriction.
网络 abcd 和网络掩码 wxyz 用于更细粒度的子网限制。
A network/nnn CIDR specification
网络/nnn CIDR 规范
Example:
例子:
Allow from 10.1.0.0/16
Similar to the previous case, except the netmask consists of nnn high-order 1 bits.
与前一种情况类似,除了网络掩码由 nnn 高位 1 组成。
回答by phihag
You cannot match an IP range with allow, but you can emulate it with a CIDR notation:
您不能将 IP 范围与allow匹配,但您可以使用 CIDR 表示法模拟它:
Order allow,deny
# 0.0.0.0 - 0.255.255.255.255
Allow from 0.0.0.0/8
# 1.0.0.0 - 1.1.255.255
Allow from 1.0.0.0/15
# 1.2.0.0 - 1.2.1.255
Allow from 1.2.0.0/23
# 1.2.2.0 - 1.2.2.255
Allow from 1.2.2.0/24
# 1.2.3.0 - 1.2.3.3
Allow from 1.2.3.0/30
# 1.2.3.4
Allow from 1.2.3.4
回答by shamittomar
Just do this for a single IP:
只需对单个 IP 执行此操作:
<Limit GET POST>
order deny,allow
deny from all
allow from 1.2.3.4
</Limit>
If you want to do it for a range like 10.x.x.x, then do this:
如果您想为 10.xxx 之类的范围执行此操作,请执行以下操作:
<Limit GET POST>
order allow,deny
allow from 10
deny from all
</LIMIT>
回答by jeevesh kumar
If you are using WordPress, then the Best and Simplest method is to install the plugin - LionScripts : WordPress IP Blockerfrom their website http://www.lionscripts.com/ip-address-blocker
如果您使用的是 WordPress,那么最好和最简单的方法是安装插件 - LionScripts:来自其网站http://www.lionscripts.com/ip-address-blocker 的WordPress IP Blocker
Their Professional version has much more features like country blocking and IP range blocking, bulk csv uploading etc.
他们的专业版具有更多功能,例如国家/地区阻止和 IP 范围阻止、批量 csv 上传等。
回答by Allahbakash.G
if you to provide a wildcard 0.0.255.255
如果您提供通配符 0.0.255.255
Order allow,deny
# 1.2.0.0 - 1.2.255.255
Allow from 1.2.0.0/16
This will give a range from 1.2.0.1 - 1.2.255.254
这将给出 1.2.0.1 - 1.2.255.254 的范围
you can also check here
你也可以在这里查看