IP ban or redirection

My previous post dealt with people hot linking to images on your website. This tutorial explains how to block users by IP or by domain from reaching your site as well as preventing other people to access your files from their site. Once again the Apache module mod_rewrite must be on for the second section of this tutorial to work.

Once again this tutorial contains a number of htaccess samples. If you are unsure about how htaccess works, then try reading the article on WikiPedia before using the contents of this tutorial.

Operator Dictionary:
! = Not
^ = Match the beginning of the search
$ = Match the end of the search

Bracket Dictionary:
[NC] = Not Case-sensitive (does not differentiate between upper and lower case)

The following sample demonstrates how to block someone by domain or by ip address:


order allow, deny
deny from http://www\.example\.com
deny from 113.337.4.311
allow from all

Line 1 starts the privileges of viewing.
Line 2 is an example showing how to block a source by domain.
Line 3 is an example showing how to block a source by IP.
Line 4 allows the site to be accessed by other sources other than those identified.

The following example demonstrates how to redirect referalls to a specific page:


RewriteEngine on
# Options +FollowSymLinks
RewriteCond %{HTTP_REFERER} example\.com [NC]
RewriteRule \.* example\.html

Line 1 turns on the engine to allow rewrite.
Line 2 is needed to be commented out depending on the Apache configuration.
Line 3 shows a referral which it will block. The [NC] is used so it is not case-sensitive.
Line 4 makes the script affect every page it will redirect to example.html if the referral page. The “\.” is used to signifiy a “.”.

The following example demonstrates how to redirect referrals to a website other then your own:


RewriteEngine on
# Options +FollowSymLinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com\.*$ [NC]
RewriteRule \.* example\.html

Line 1 turns the rewrite engine on.
Line 2 is needed to be commented out depending on the Apache configuration.
Line 3 checks if there is a referrer.
Line 4 checks if the referrer is not your site. Replace “mydomain” with your domain.
Line 5 redirects it to example.html if it has a referrer that is not your site.

Digg This

6 Responses to “IP ban or redirection”

  1. koju Says:

    http://dfgree.sblog.cz

  2. aas Says:

    enioomassa

  3. fajdx Says:

  4. my blog Says:

    check this out…

    this is mine…

  5. My Domain Says:

    Joe…

    Check out my domain sometime….

  6. Cheap iPad Says:

    iPad Real Store…

    Add an iPad 3G to your life and you can toss the eBook readers, GPS units, and probably an old laptop or two. Life is too full of gadgets, iPad is unify where you can….

Leave a Reply