阻止欧盟国家通过.htaccess访问我的网站?

时间:2018-05-25 18:02:16

标签: html .htaccess block country

您好我有几页的基本HTML网站。我想通过我的根目录中的.htaccess文件阻止来自欧盟国家的访问。我在htaccess文件的顶部插入了这段代码,但似乎没有做任何更改。

<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>

有人可以帮我这个吗?由于mod_geoip.c未启用,因此模块未启用cPanel?

1 个答案:

答案 0 :(得分:1)

我建议在另一个网站上创建一个页面,让他们知道他们特别是由于GDPR而失去了对您网站的访问权限。然后,来自欧盟国家的访客将被重定向到该页面。

您需要具有sudo权限并正在运行Apache,因为这需要IP2Location Apache模块才能运行。

您可以使用它来生成代码: https://www.ip2location.com/free/visitor-redirection#source-codes

代码:

    <!-- 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]