Placed in: Home arrow Useful arrow How to arrow Ban users from your website using the .htaccess file viagra australia
viagra online
viagra sale
cialis online
cialis australia
Ban users from your website using the .htaccess file

Do you want to ban people from your website? Of course you can code this in PHP, but the most efficient way to do it, is to put it in the .htaccess file of your host. This way, you can also disable hotlinking of images or other files that are hosted on your website.

Keep your website yours, don't let it be taken over by useless spammers, bots and other annoying people.

Be careful when banning entire ranges of IPs, as you may also be blocking legitimate traffic!

User IP Ban

Valid entries:
IP-addresses should have this format:

xxx.xxx.xxx.xxx
, where "xxx" is a number between 0 and 255. In the .htaccess files you can specify a certain IP from your site, but you can also block full ranges.
Examples:
  • 42.13.6.32
    Block the specific IP address
  • 212.172.49.
    Blocks all IP's from the range:
    212.172.49.xxx
  • 69.241.
    Blocks all IP's from the range:
    69.241.xxx.xxx
  • 81.143.4
    Blocks all IP's from the range:
    81.143.4xx.xxx.xxx

To actually set the User IP Ban, put this code in your .htaccess file of your server (or create one of your own):

## USER IP BANNING
<Limit GET POST>
 order allow,deny
 deny from 42.13.6.32
 deny from 212.172.49.
 deny from 69.241.
 deny from 81.143.4
 allow from all
</Limit>

Site Referrer Ban

Example Valid entries:

  • somesite.com
    Blocks traffic from somesite.com
  • somesite.
    Blocks traffic from any site starting somesite.xxx, like somesite.com, somesite.net etc.
  • subdomain.somesite.com
    Blocks traffic from subdomain.somesite.com
  • 42.13.6.32
    Blocks traffic coming from a particular site IP

To set an Site Referrer Ban, put this code in your .htaccess file:

## SITE REFERRER BANNING
RewriteEngine on
# Options +FollowSymlinks
 
RewriteCond %{HTTP_REFERER} somesite.com [NC,OR]
RewriteCond %{HTTP_REFERER} somesite. [NC,OR]
RewriteCond %{HTTP_REFERER} subdomain.somesite.com [NC]
RewriteRule .* - [F]

*Note: Do not include "http://www." portion of the URL*

Disable hotlinking

Example Valid entries for Allowed domains / IPs:

  • marcofolio.net
    Allow this domain to access the restricted file types
  • subdomain.marcofolio.net
    Allow this subdomain to access the restricted file types
  • 195.47.247.126
    Allows this site IP to access the restricted file types

Example Valid entries for List of file types:

  • gif
    Disallow hotlinking of *.gif files on the server
  • jpg
    Disallow hotlinking of *.jpg files on the server
  • css
    Disallow hotlinking of *.css files on the server, so blank file is served instead
  • js
    Disallow hotlinking of *.js files on the server, so blank file is served instead

To Disable hotlinking, put this code in your .htaccess file:

## DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?marcofolio.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?subdomain.marcofolio.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?195.47.247.126/.*$ [NC]
RewriteRule .(gif|jpg|css|js)$ - [F]

*Note: Only include the allowed domain names. Your own domain is automaticly allowed to access the files.*

Good luck using this knowledge, get rid of those annoying people.


Tags:  ban website design htaccess internet

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio