Free Geo-Block & Bot Filter Generator
Block fraud traffic, scrapers and bots from your website in seconds. Generate copy-paste code for Cloudflare, Vercel, WordPress, Shopify and 6 more platforms. Designed for businesses that need to focus on their target markets.
Before you block anyone — read this first
Blocking traffic by country is sometimes legitimate (e.g. you only ship to the UK, you only operate in specific markets, or you've measured high fraud rates from a region). But it can also be discriminatory if used carelessly — and it can have legal implications depending on your jurisdiction.
Our recommendation: start with bot, VPN and datacenter blocking. This removes 80% of low-quality traffic without restricting any real human visitor. Only add country blocking if you have a documented business reason. Prefer allow-listing your target markets over blocking other countries.
This tool generates code — you are responsible for how you use it.
Step 1 — Pick a strategy
Choose your starting point
Pick one. You can refine the details below — picking a strategy is a starting point, not a commitment.
Step 2 — Pick your mode
Allow-list or block-list?
Allow-listing is usually safer and easier to maintain. Use block-list mode only when you need to restrict a small number of specific regions.
Block bots, scrapers and anonymisers
RecommendedThe ethical, precise way to remove low-quality traffic. Each category targets automated traffic — bots, scrapers, datacenter IPs, anonymisers — with virtually zero impact on real human visitors.
Country restrictions
Use sparinglyTick the countries where you want to allow access. Everyone else will be blocked.
Quick allow-list
No countries match your search.
Block action
What happens when a visitor matches your rules.
Relative path (e.g. /region-not-served) or full URL.
Pick your platform
Same configuration, generated for whichever stack you run. Cloudflare is recommended — it works with any underlying platform and has the richest bot signals.
The basics
What is geo-blocking?
What it is
Geo-blocking is the practice of restricting website access based on the visitor's location, IP address, or network behaviour. It happens at the network or application layer — the visitor either never reaches your server, or reaches it but is rejected. Major businesses use it for licensing compliance, fraud prevention, regulatory requirements, and market focus.
Bots vs countries
Most "bad traffic" attributed to specific countries is actually bot traffic, scraper traffic, or VPN-routed traffic from elsewhere. Blocking by country is a blunt instrument that affects real humans. Blocking bots and datacenter IPs is precise — it affects only automated traffic. Start with bot blocking. Add country blocking only if you have measured a specific business need.
What about SEO indexing?
You cannot directly tell Google "don't index my site in Pakistan" — Google's index is global. What you can do: use hreflang tags to declare which countries each page targets, set geographic targeting in Google Search Console, use a country-specific TLD (.co.uk, .de, .fr) for strong country signals, and build country-specific backlinks from your target markets. These are separate from blocking traffic.
Decision guide
Should I block entire countries?
An honest walkthrough of when country blocking is reasonable, when it isn't, and what to try first.
When country blocking IS reasonable
- You operate a physical service in a specific region only
- You only ship to specific countries
- You're legally required to restrict by region (licensing, sanctions)
- You have documented, measurable fraud rates above ~5% from a region
- Your terms of service explicitly require it
When country blocking is NOT reasonable
- You "just have a feeling" certain regions are problematic
- You haven't tried bot / VPN filtering first
- You're blocking based on assumptions about people, not measured fraud
- Your business operates globally but you find the traffic "annoying"
Better alternatives to try first
- Bot, datacenter and VPN blocking (this tool, top option)
- Address verification and 3D Secure at checkout
- Stripe Radar or similar fraud-scoring rules
- CAPTCHA on contact and signup forms
- Honeypot fields on forms
- Rate limiting per IP
Heads up
Legal considerations
- GDPR: EU residents have a right to access information you publish. Blocking EU traffic outright may have compliance implications if you already process EU personal data.
- ADA / accessibility: US accessibility law applies to US-targeted businesses; a wholesale US block likely doesn't trigger ADA but consult a qualified solicitor before deploying.
- Discrimination laws: Some jurisdictions classify nationality as a protected characteristic. Country blocking for a non-business reason could expose you to liability.
- Sanctions compliance: Some countries (Cuba, Iran, North Korea, Syria) you may actually be required to block under US, UK or EU sanctions.
This is general information, not legal advice. Consult a qualified solicitor before deploying country-level restrictions on a commercial site, especially if you process personal data or operate across jurisdictions.
Step 3 — Deploy it
Platform deployment guides
Exact step-by-step for every supported platform. Pick yours, follow the steps, verify with a VPN test.
Why we recommend Cloudflare first. Rules apply at the edge before traffic ever hits your origin server — so there is zero performance impact on real visitors and zero load on your hosting. Cloudflare also has built-in bot scoring, VPN detection and threat-score signals you cannot easily replicate elsewhere. The free tier covers up to five custom rules, which is plenty for most small business sites.
Step-by-step
- Create a Cloudflare account at cloudflare.com and add your domain.
- Update your DNS to use the Cloudflare nameservers shown during setup. (This is the only fiddly step — once it's done, you're done.)
- Cloudflare dashboard → Security → WAF → Custom rules.
- Click Create rule.
- Give the rule a name (e.g. "SEO First Web — Geo + Bot Block").
- Click the Edit expression link to switch to the expression editor.
- Paste the generated expression from the output panel above.
- Set the action to Block for hard enforcement, or Managed Challenge for a soft check (visitors see a brief CAPTCHA-style challenge).
- Click Deploy.
Test it
- Use a VPN to switch your apparent country, then visit your site.
- You should see either a 403 page, your redirect, or the challenge — depending on what action you chose.
- In Cloudflare dashboard → Security → Events, you can see every rule hit in real time.
Use Workers when you need more control than firewall rules give you — custom redirect pages, soft-blocks that allow browsing but block checkout, conditional logic based on path, or A/B testing different actions.
- Cloudflare dashboard → Workers & Pages → Create application → Create Worker.
- Give it a name (e.g. "geo-block").
- In the code editor, paste the generated Worker script from the output panel above.
- Click Save and deploy.
- Workers dashboard → your worker → Triggers → Add route.
- Add a route pattern like
yourdomain.com/*matching your zone. - Deploy.
If your site is hosted on Vercel, this is the simplest option — no extra services or DNS changes, just one file in your repo.
- Create
middleware.tsin your project root (orsrc/middleware.tsfor Astro / src-based layouts). - Paste the generated middleware code from the output panel above.
- Commit and push — Vercel auto-deploys.
- No environment variables, no config changes — Vercel's edge runtime resolves
request.geoautomatically.
Generic Next.js middleware that works on any host — Vercel, AWS Lambda, Netlify, self-hosted Node. Reads geo from request headers when available, falls back to a free IP-lookup service.
- Create
middleware.tsin your Next.js project root. - Paste the generated code from the output panel above.
- If you're self-hosting (not on Vercel or Cloudflare), the fallback uses
ipapi.co. For production traffic, swap to a paid GeoIP provider like MaxMind GeoIP2 or ipinfo.io. - Deploy — middleware runs automatically on every matched route.
For Astro projects running in SSR mode. Works behind any reverse proxy that sets a country header — Vercel, Cloudflare, Netlify all set one by default.
- Make sure your Astro project is in SSR mode — add the Vercel, Netlify or Node adapter to
astro.config.mjs. - Create
src/middleware.ts. - Paste the generated code from the output panel above.
- Commit and deploy.
WordPress has no native GeoIP support, so we use the popular GeoIP Detection plugin (5+ million active installs, GPL, free) to read the visitor's country, then enforce in functions.php.
Step 1 — Install the plugin
- WP Admin → Plugins → Add New.
- Search for "GeoIP Detection" by Yellow Tree.
- Install and activate.
- WP Admin → Settings → GeoIP Detection.
- Choose "Use Maxmind Geolite Database (Free)" as the source and click Save & Download.
Step 2 — Add the snippet
- Back up your site first — functions.php errors can take your whole site offline.
- WP Admin → Appearance → Theme File Editor.
- Select functions.php.
- Paste the generated PHP at the very bottom (after any existing code).
- Click Update File.
- Test by visiting your site via a VPN.
If your only goal is to not sell to certain countries (rather than block them from the site entirely), WooCommerce's built-in settings cover everything — no code required.
- WP Admin → WooCommerce → Settings → General.
- Selling location(s) → choose "Sell to specific countries" and pick your target markets. Or "Sell to all countries, except…" if you only want to exclude a few.
- WooCommerce → Settings → Shipping → Shipping zones.
- Only add zones for the countries you actually ship to. Customers from unlisted countries cannot complete checkout.
- (Optional) Pair with the WordPress functions.php snippet on the previous tab if you want to block visitors from reaching the site at all.
Shopify's built-in Markets feature is the strongest geo-control they offer — disable a market and visitors from that country lose access to checkout entirely. The Liquid snippet adds browse-level enforcement on top.
Step 1 — Configure Markets
- Shopify Admin → Settings → Markets.
- Click Manage markets.
- Disable any market you do not want to serve, or set up specific country lists per market.
- Save.
Step 2 — Add the Liquid snippet (optional)
- Shopify Admin → Online Store → Themes.
- Click Actions → Edit code on your live theme.
- Open
layout/theme.liquid. - Paste the generated snippet at the very top of the
<body>tag (before anything else renders). - Save.
For sites on Apache (most shared hosting). Requires mod_geoip or the newer mod_maxminddb to be enabled.
Step 1 — Verify GeoIP is available
- Create a temporary
info.phpfile in your site root with<?php phpinfo(); ?>inside. - Visit
yourdomain.com/info.phpand search for "geoip" or "maxmind". - If you see GeoIP enabled, you're ready. If not, contact your host — most can enable it on request.
- Delete info.php after testing — leaving it exposed is a security risk.
Step 2 — Add the rules
- Connect via FTP / SFTP / cPanel File Manager.
- Edit
.htaccessin your site root (create it if it doesn't exist). - Paste the generated rules from the output panel above.
- Save.
For self-hosted Nginx servers (Linode, DigitalOcean, AWS EC2, etc.). Requires the ngx_http_geoip2_module and a MaxMind GeoLite2 country database.
- SSH into your server.
- Install the module:
apt-get install libnginx-mod-http-geoip2(Debian / Ubuntu). - Download the free GeoLite2-Country database from MaxMind (free account required).
- Place the .mmdb file at
/etc/nginx/GeoLite2-Country.mmdb. - Open your Nginx config:
sudo nano /etc/nginx/nginx.confor your site config. - Paste the HTTP-context block at the top, then the server-context block inside your
server { }block. - Test the config:
sudo nginx -t— fix any reported errors. - Reload:
sudo systemctl reload nginx.
Frequently asked questions
The questions we hear most from clients setting up geo-blocking for the first time.
Will geo-blocking hurt my SEO?
Not if done correctly. Bot and datacenter blocking has zero SEO impact — verified search-engine crawlers (Googlebot, Bingbot, DuckDuckBot) are exempted automatically on Cloudflare and we hard-code an exemption in the WordPress and Worker templates. Country blocking can affect your indexing in those countries' Google results, but if you do not operate in those markets that is the point. The key rule: always allow Googlebot, Bingbot, and the other major search crawlers. This tool defaults to that.
What's the difference between blocking countries and blocking bots?
Country blocking restricts real human visitors based on their IP location — a blunt instrument that affects a wide population. Bot blocking restricts automated traffic from known bot networks, scrapers, and datacenter IPs — a precise instrument that affects only automated traffic. Bot blocking is the recommended starting point for almost any site. Country blocking should only be used when you have a documented business reason (you only ship to certain countries, you only operate in certain markets, you have measured high fraud rates from a specific region).
Will Cloudflare's free tier handle this?
Yes for most small and medium sites. The Cloudflare free plan includes 5 custom firewall (WAF) rules — plenty for a comprehensive country and bot block. For advanced bot management with machine-learning scoring, VPN detection, or rule analytics, you would need Cloudflare Pro (~$20/month) or Business. The expression generated by this tool works on any tier.
Can I block Google or Bing accidentally?
This tool always allows verified search-engine crawlers (Googlebot, Bingbot, DuckDuckBot, Applebot, Slurp) by default — Cloudflare's "verified bot" exemption applies automatically to firewall rules, and our Worker and WordPress templates hard-code an exemption for these user agents. As long as you do not manually add a search engine to your block list, your SEO is safe.
What about VPN users who are legitimate customers?
This is a real trade-off. Blocking VPNs will block some legitimate privacy-conscious users — roughly 10–20% of UK and EU adults use a VPN at least occasionally. The way to handle it: use the "Allow browsing, block checkout / forms" action mode so VPN users can still read your content (preserving SEO traffic), but are stopped at the point where fraud actually happens. Or use a soft challenge (Cloudflare Managed Challenge) instead of a hard block — legitimate users solve it in 2 seconds, bots fail.
How accurate is IP geolocation?
Roughly 95% accurate at the country level, 75% at the city level. Mobile IPs and VPNs degrade accuracy further. Never use IP geolocation for anything mission-critical — for example, for shipping decisions or legal compliance, use the customer-confirmed billing address at checkout, not their browsing IP. Geo-blocking with IP is fine for fraud prevention and market focus because the cost of a false positive is recoverable (the visitor can contact you), but use it as one signal among several rather than the only one.
Can I block specific cities or regions within a country?
Yes, on Cloudflare and Nginx (with the right database — GeoLite2-City instead of GeoLite2-Country). The generated code in this tool focuses on country-level since that is what 99% of business use cases need. For city or region-level enforcement, you would extend the rules manually using ip.geoip.city on Cloudflare or $geoip2_city_name on Nginx.
Does this work for Squarespace, Wix, or other no-code platforms?
Not directly — Squarespace and Wix do not let you run middleware or edit server configs. The workaround is to put Cloudflare in front of your site (point your DNS through Cloudflare, even though your hosting stays the same), then apply rules at the Cloudflare level. The Cloudflare tab of this tool produces code that works for any underlying platform, including Squarespace, Wix, Webflow, GoDaddy, or any other hosted website builder.
How do I test my geo-block is working?
Three options. (1) Use a VPN to switch your apparent location and visit your site — you should see whichever action you configured (403, redirect, or soft-block). (2) Use a free service like geopeeker.com or webpagetest.org to render your site from different geographic locations. (3) On Cloudflare specifically, the Security → Events dashboard shows every rule hit in real time, so you can confirm rules are firing as expected.
Should I block by country or by language?
Different things. Country = IP location. Language = browser Accept-Language header. If your concern is fraud prevention, country is more relevant (fraudsters route through their actual location, but mostly speak the language of their target). If your concern is content localisation — showing French content to French users — language is more relevant. This tool handles country; for language redirects, you would use a separate piece of logic that reads Accept-Language at request time.
Not sure what's draining your conversion rate?
Our team can run a full traffic-quality audit and identify exactly where your fraud, bot and low-value traffic is coming from — and how to stop it.
Book a Free ConsultationOther free SEO tools
Robots.txt Generator
Block AI crawlers, scrapers and search bots at the protocol layer. 18 AI bot controls included.
Open tool →SEO Audit
Full-site SEO audit in 30 seconds — Lighthouse scores, security grade, on-page checks.
Open tool →Schema Validator
Paste any URL, see every schema block, plain-English fixes for what's broken.
Open tool →