.htaccessip-blocking

Blocking ip with htaccess


I have a htaccess file with following code when trying to block an IP:

DirectoryIndex index.php index.html

ErrorDocument 404 /errors.php

Order Allow,Deny
Deny from 188.143.232.
Allow from all

Blocking my own IP works when browsing www.example.com, but it does not block for anything else (like www.example.com/index.php or www.example.com/home, ....). The htaccess is located in the same directory as index.php (httpdocs folder).

How can I get it to work?


Solution

  • You can also use a mod-rewrite based ip-blocking to block unwanted ip(s) :

    RewriteEngine on
    
    #--if client ip==188.143.232
    RewriteCond %{REMOTE_ADDR} ^188\.143\.232
    #--forbid the request
    RewriteRule ^ - [F,L]