如果您不想让某个ip地址访问您的网站,或者不让某些ip段访问您的网站。一般是防止恶意访问,防止网站被采集等。
在云虚拟主机中,屏蔽指定IP地址请参考如下几种方法。
第一种:
通过.htaccess文件屏蔽
通过配置.htaccess文件屏蔽指定IP地址,.htaccess文件中需要配置的代码如下。
RewriteEngine on
RewriteBase /
Order Deny,Allow
Deny from [$Deny_IP]
Deny from [$Deny_IP_Segment]
注:[$Deny_IP]为需要屏蔽的IP地址,可添加多个要屏蔽的IP地址,中间用空格隔开。
[$Deny_IP_Segment]为需要屏蔽的IP地址段。
第二种方法:
使用ASP屏蔽IP地址将以下代码添加到ASP页面中,用以屏蔽指定IP地址。
<%requestIP = request.ServerVariables(“REMOTE_ADDR”)IP = “[$Deny_IP]”
trueURL = “http://www.输入网址1.com“
falseURL = “http://www.输入网址2.com“
ipArr = split(IP,”|”)
flag = false
for i=0 to ubound(ipArr)
if requestIP=ipArr(i) then
flag=true
exit for
end if
next
if flag then
response.Redirect(falseURL)
else
response.Redirect(trueURL)
end if
%>
注:[$Deny_IP]为需要屏蔽的IP地址,可添加多个要屏蔽的IP地址,中间用|隔开。
注意:适用于虚拟云主机。
原文:https://www.cnblogs.com/leifeng666/p/13110332.html