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]

  • 20 Users Found This Useful
Was this answer helpful?

Related Articles

Do you support mod_rewrite for apache?

Yes, mod_rewrite is enabled on your server. For more information on what mod_rewrite is and how...

How to execute php code as .htm or .html files

In your .htaccess file insert this line of code. addhandler application/x-httpd-php .htm .html

Disabling Magic Quotes GPC

How to turn off magic quotes gpc (required by Joomla 3 and some other scripts).1. Create a...

Block Bad Bots and Spiders using .htaccess

Below is a useful code block for blocking a lot of the known bad bots and site rippers currently...

.htaccess RewriteRule Examples

Here are some useful mod_rewrite RewriteRule redirect examples that you can use in your .htaccess...