Follow

Block a specific IP address from accessing your website

  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 15
    • Tools Required: FTP client, plain text editor
  • Applies to: All DV
    • Difficulty: Easy
    • Time Needed: 10
    • Tools Required: FTP client, plain text editor

Overview

If you have annoying visitors, site scrapers, or spammers, you may find it useful to block these users from accessing your website content. You can block bad visitors by IP address or blocks of IP addresses using a .htaccess file. Below are some useful examples:

Requirements

Before you start, be sure to have handy:

READ ME FIRST
This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

READ ME FIRST
The publishing of this information does not imply support of this article. This article is provided solely as a courtesy to our customers. Please take a moment to review the Statement of Support.

Instructions

Secure directories by IP address and/or domain

In the following example, all IP addresses and domains are accepted, except for xxx.xxx.xxx.xxx and example.com:


# allow all except those indicated here
<Files *>
order allow,deny
allow from all
deny from xxx.xxx.xxx.xxx
deny from .*example\.com.*
</Files>

In the following example, all IP addresses are denied access except for xxx.xxx.xxx.xxx and example.com:


# Deny access to everyone, except those listed here:
<Files *>
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
allow from .*example\.com.*
</Files>

This next example provides steps to block unwanted visitors based on the referring domain. Simply replace "baddomain01″ and "baddomain02″ with the offending domains of your choice:


# block visitors referred from indicated domains
RewriteEngine on
RewriteCond %{HTTP_REFERER} baddomain01\.com [NC,OR]
RewriteCond %{HTTP_REFERER} baddomain02\.com [NC]
RewriteRule .* - [F]

Resources

Was this article helpful?
1 out of 1 found this helpful

Comments