Logo Your Web Hosting Solution
Line
.htaccess Guide
Introduction
Directory Listing
Error Messages
Password Popup
Redirect Pages
Protect Images
Block Users
.htaccess Tools
Tutorials Index
Home Page
.htaccess Tutorial - Block An IP Address

There may be times where you want to refuse access to certain robots or human visitors to your web site.

1. Basic .htaccess file

order allow,deny
deny from 127.0.0.1
allow from all

This will refuse all GET and POST requests made by IP address 127.0.0.1, an error message is shown instead.

2. More options

To block multiple IP addresses, list them one per line.

order allow,deny
deny from 127.0.0.1
deny from 127.0.0.2
deny from 127.0.0.3
allow from all

You can also block an entire IP block/range. Here we will not specify the last octet in the .htaccess file.

deny from 127.0.0

This will refuse access for any user with an address in the 127.0.0.0 to 127.0.0.255 range.

Instead of using numeric addresses, domain names (and subdomain names) can be used to ban users.

deny from isp_name.com

It bans users with a remote hostname ending in isp_name.com. This would stop all users connected to the internet via isp_name.com from viewing your site.

Using .htaccess to block an entire range or name is likely to lock out innocent users. Use with caution.

Top Of Page 
Line
Copyright© 1996 - 2024 Clockwatchers, Inc.