Search code examples
.htaccessblockaccess-deniedgeoiprestrict

Block country for special address or URL with htaccess and GeoIP


I want restrict access one or more specific country IPs for URL or address such as "/cart.php?a=checkout". How can do this with htaccess and Geo-IP mod ?


Solution

  • for example you can use this code:

    <FilesMatch "^(cart\.php|viewinvoice\.php)$">
    
    SetEnvIf GEOIP_COUNTRY_CODE DE BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE IN BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE UA BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE EC BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE VN BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE AM BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE LV BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE US BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE TR BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE FR BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE SA BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE PL BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE NL BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE SG BlockCountry
    
    Order allow,deny
    Allow from all
    Deny from env=BlockCountry