ban country with mod_rewrite without mod_geoIP

Discussion in 'Apache' started by linux_administrator, Apr 6, 2007.

  1. #1
    Hi

    I want to block certain countries from visiting my site for this I have written a test.php page which test the ip of the user against a table and then take the decision whether to send the user to the site or back to the block message page...

    I am using this htaccess code


    Code:
    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^.*test\.php.*$
    RewriteRule ^(.*)$ test.php?var1=$1 [L]
    </IfModule>

    means, if the URL is not domain.com/test.php send the user to test.php page for checking his ip....

    now when test.php page sends user back to the exact URL he puts to visit the page )($var1) the user is again redirected because the htaccess rule again matches...

    How can I prevent it from looping so that if a user is already checked for his IP he should not be checked again?

    my host doesn't support mod_geoip, and I can only use htaccess with mod rewrite.I dont want to make a 100 MB htaccess by manually defining ip ranges for these countries so want to do it with mod_geoip kinda method.

    any help is highly appreciated...
     
    linux_administrator, Apr 6, 2007 IP