Running a blog for decades means accumulating a vast archive of thoughts and history. To protect this archive from being scraped, aggregated, or taken out of context by aggressive crawlers from specific regions, I have actually been restricting access from specific regions since 2024. I initially relied on Cloudflare’s WAF rules to handle this, but to gain more flexibility and granular control over the traffic, I recently decided to shift this logic directly into WordPress.
To achieve this, I put together a lightweight tool: the WP Country IP Blocker. It is a simple, personal-use plugin designed to restrict access based on standard country codes. Instead of relying on a rigid firewall block that causes a harsh page crash, this plugin allows me to serve a custom HTTP status code alongside a polite message explaining that the blog’s services are currently restricted in the visitor’s region.
Under the hood, the plugin runs quietly in the background, reliably fetching and caching IP routing data from sources like the v2fly/geoip database. Overall, it serves as a low-maintenance safeguard, offering flexible configuration and low cost.
发表回复