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:
- Familiarity with the use of FTP and an FTP client.
- Your FTP login credentials and an FTP client.
- Plain text editor
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
- askapache.com
- Using .htaccess files
- Using .htaccess files
- How do I redirect my site using a .htaccess file?
- Prevent hotlinking with a .htaccess file
- Prevent hotlinking with a .htaccess file
- Making directories browsable, solving 403 errors
- Making directories browsable, solving 403 errors
- Using rewrite rules
- Using rewrite rules
Comments