Block IP addresses Using .HTACCESS

Hello Friends !!

In my previous post, i was write how to block IP address using PHP script ?

Today i will write that how to block IP address using .HTACCESS ?

There are several ways to block a specific IP range.

The first utilizes a CIDR number to block the specified range (via htaccess):

# block IP range by CIDR number
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 214.53.25.64/26
</Limit>


The second method is similar, only here we are expressing the range in netmask notation, using corresponding network/netmask values:

# block an IP range via network/netmask values
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 214.53.25.64/255.255.255.192
</Limit>

The third method tests all IP addresses against a predefined regular expression via RewriteCond/RewriteRule directives:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^214\.53\.25\.(6[4-9]|7[0-9]|8[0-9]|9[0-9])$ [OR]
RewriteCond %{REMOTE_ADDR} ^214\.53\.25\.1([0-1][0-9]|2[0-8])$
RewriteRule .* – [F]

Here is a way of blocking a specific ISP via its IP address(es).

<Files *>
Order Allow,Deny
Allow from all
Deny from 123.123.123.
Deny from 456.456.456.
</Files>

There is probably a more efficient way to write the regular expressions in the previous example, but that should definitely get the job done.

I think this post become useful to you.

  • http://www.mavenmullet.com/ srganesan

    HI

    this tutorial is very help ful for me thanks 😀

  • http://www.mavenmullet.com srganesan

    HI

    this tutorial is very help ful for me thanks 😀

  • http://JoshuaXiong.Webs.Com/ JoshuaXiong

    HI

  • http://JoshuaXiong.Webs.Com JoshuaXiong

    HI

  • Pingback: 網站製作學習誌 » [Web] 連結分享()

  • Pingback: Tagz | "Block IP addresses Using .HTACCESS | php genious" | Comments()

  • GarrySch

    Someone help me, please. I am not able to get my .htaccess file to work. It crashes the site. I know my problem lies with the syntax prior to the .

    Thanx.

    Garry
    garrysch@swbell.net

  • GarrySch

    Someone help me, please. I am not able to get my .htaccess file to work. It crashes the site. I know my problem lies with the syntax prior to the .

    Thanx.

    Garry
    garrysch@swbell.net

  • Guest

    how can i block a ip range like this
    5.8.12.0.0 — 5.8.255.255

  • phpgenious

    5.8.12.0.0 ? Is it right address ? Please provide right address range .

  • Gelso Giuseppe

    sbolck my ip for use skype

  • Gelso Giuseppe