- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 3.0
- » Web Applications
- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 3.5
- » Web Applications
- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 3.0
- » Web Applications
- » PHP and Coding
- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 3.5
- » Web Applications
- » PHP and Coding
- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 4.0
- » Web Applications
- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 4.0
- » Web Applications
- » PHP and Coding
Block a specific IP address from accessing your website
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:
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
User Comments
No visitor comments posted. Post a comment
Fields marked with an asterisk(*) are required. Comment on this article