Skip to content

Instantly share code, notes, and snippets.

@matsuu
Forked from zero-master/GDPR.md
Last active May 21, 2021 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuu/4619fe7ae808f2adbcf24e57b6049413 to your computer and use it in GitHub Desktop.
Save matsuu/4619fe7ae808f2adbcf24e57b6049413 to your computer and use it in GitHub Desktop.
Show visitors from EU countries a page with GDPR message using Cloudflare and .htaccess

Turn on Cloudflare IP Geolocation

https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-Cloudflare-IP-Geolocation-do-

In your .htaccess file:

RewriteEngine on
RewriteCond %{HTTP:CF-IPCountry} ^(AT|BE|BG|CY|CZ|DK|EE|FI|FR|DE|GR|HU|HR|IE|IT|LV|LT|LU|MT|NL|PL|PT|RO|SK|SI|ES|SE|GB)$
RewriteCond %{REQUEST_URI} !^/blockedGDPR/
RewriteRule ^ - [F,L]

ErrorDocument 403 /blockedGDPR/

Create a file named index.html in blockedGDPR directory with the below content:

<html>
  <title>
   GDPR Block
  </title>
  <body>
  We are unable to bear GDPR compliance cost at the moment.
  </body>
  <style>
    body {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      color: #2c3e50;
      margin-top: 20px;
    }
    </style>
    
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment