Block visitors by IP address using .htaccess

Deny access based upon IP address, or an IP block, by placing the following code into your .htaccess file.

#Block access to IP address 192.168.169.170 and to IPs beginning with 192.168.169.
order allow,deny
deny from 192.168.169.170
deny from 192.168.169.
allow from all

#Block access to All visitors except yourself (What is My IP Address)
order allow,deny
allow from 192.168.169.170
deny from all

---

Using mod_rewrite is an alternative method for blocking IP addresses with .htaccess:

#Block access to IP address 192.168.169.170
RewriteEngine on
RewriteCond %{Remote_Addr} ^192\.168\.169\.170$
RewriteRule ^(.*) http://localhost/ [R,L]

#Block access to IP addresses from 192.168.0.0 to 192.168.255.255
RewriteEngine on
RewriteCond %{Remote_Addr} ^192\.168
RewriteRule ^(.*) http://localhost/ [R,L]

Was this answer helpful?

Also Read

.htaccess 301 Redirect Generator

A simple .htaccess 301 redirect generator to be used to create SEO friendly permanent redirects....

Secure Joomla with .htaccess

Advanced .htaccess rules that will overall secure and increase the speed of your Joomla...

Resolving XMLRPC DDoS WordPress Attack with .htaccess

Brute Force Attacks against WordPress have always been very common.Here is how to temporarily...

Redirect non-www to www over http and https

Use the following .htaccess code to redirect non-www URLs to www over http and https. Create, or...

How to Remove Multiple Slashes from URL

You can use this .htaccess rule for removing multiple trailing slashes anywhere in URL:...