Reputation: 43
Hi i have basic HTML site with a few pages. I want to block access from EU countries via .htaccess file i have into my root dir. I inserted this code on top of htaccess file, but seems that not make any changes.
<ifModule mod_geoip.c>
GeoIPEnable On
# Add countries you wish to deny here
SetEnvIf GEOIP_COUNTRY_CODE AL DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE AD DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE AM DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE AT DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE AM DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE AZ DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE BY DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE BE DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE BA DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE BG DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE HR DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE CY DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE CZ DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE DK DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE EE DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE FI DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE FR DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE GE DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE DE DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE GR DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE HU DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE IS DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE IE DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE IT DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE KZ DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE LV DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE LI DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE LT DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE LU DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE MK DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE MT DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE MD DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE MC DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE ME DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE NL DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE NO DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE PL DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE PT DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE RO DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE RU DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE SM DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE RS DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE SK DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE SI DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE ES DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE SE DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE CH DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE TR DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE UA DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE GB DenyCountry
SetEnvIf GEOIP_COUNTRY_CODE VA DenyCountry
Allow from all
Deny from env=DenyCountry
</ifModule>
Can someone to help me with this? Maybe not works due to mod_geoip.c is not enabled as module into cPanel?
Upvotes: 0
Views: 1428
Reputation: 59
I recommend making a page on another website letting them know that they have lost access to your site specifically due to GDPR. Then a visitor from an EU country would be redirected to that page.
You would need to have sudo permissions and be running Apache, because this requires the IP2Location Apache Module in order to run.
You can use this to generate the code: https://www.ip2location.com/free/visitor-redirection#source-codes
Code:
<!-- language: htaccess -->
RewriteEngine On
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^AT$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^BE$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^BG$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^HR$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^CY$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^CZ$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^DK$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^EE$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^FI$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^FR$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^DE$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^GR$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^HU$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^IE$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^IT$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^LV$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^LT$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^LU$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^MT$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^NL$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^PL$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^PT$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^RO$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^SK$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^SI$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^ES$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^SE$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^GB$
RewriteRule ^(.*)$ https://example.com/gdpr-page/ [L]
Upvotes: 1