Overview
The Block Specific Countries feature in AdminEase allows you to automatically block visitors from specific countries by generating .htaccess rules that deny access based on the visitor’s country code. This feature works best with Cloudflare and it should be active on for your domain, GeoIP is used as fallback incase Cloudflare is inactive.
Prerequisites
Don’t have Cloudflare? Sign up for free at cloudflare.com
Cloudflare Setup
- Create a Cloudflare account at cloudflare.com
- Add your domain to Cloudflare
- Update your DNS nameservers to point to Cloudflare
- Enable proxy mode (orange cloud) for your domain records
- Wait for activation – Cloudflare will automatically add country headers to requests
How It Works
Country Detection
- Uses Cloudflare’s
CF-IPCountryheader to identify visitor locations - Works automatically once Cloudflare is properly configured
- No additional setup required on your server
Blocking Mechanism
- Generates Apache
.htaccessrules usingmod_rewrite - Blocks happen at the server level before WordPress loads
- Returns HTTP 403 Forbidden error to blocked visitors
- Rules are added at the top of
.htaccessfor optimal performance
Using the Feature
Step 1: Access AdminEase Settings
- Go to your WordPress admin dashboard
- Navigate to AdminEase in the main menu
- Click on the Security tab
Step 2: Configure Country Blocking
- Find the Block Specific Countries section
- Toggle the feature ON
- Use the country selection field to choose which countries you want to block by selecting them from the dropdown list
Step 3: Save Settings
- Click Save Settings
- The feature will automatically generate and add the blocking rules to your
.htaccessfile - Changes take effect immediately
Generated .htaccess Rules
When you save settings, AdminEase automatically generates rules like this:
# ADMINEASE_BLOCK_SPECIFIC_COUNTRIES START
<IfModule mod_rewrite.c>
RewriteEngine On
# Cloudflare compatibility
RewriteCond %{HTTP:CF-IPCountry} ^CN$ [OR]
RewriteCond %{HTTP:CF-IPCountry} ^RU$ [OR]
RewriteCond %{HTTP:CF-IPCountry} ^KP$
RewriteRule .* - [F]
</IfModule>
# ADMINEASE_BLOCK_SPECIFIC_COUNTRIES END
Performance Benefits
Server-Level Blocking
- Efficient Processing: Uses Apache’s
mod_rewritefor fast blocking - No PHP Overhead: Blocks happen before WordPress loads
- Reduced Server Load: Blocked requests consume minimal resources
Cloudflare Integration
- Edge Network: Leverages Cloudflare’s global infrastructure
- Accurate Detection: Uses Cloudflare’s extensive IP database
- Automatic Updates: Country data is maintained by Cloudflare
Troubleshooting
Feature Not Working?
Check Cloudflare Status:
- Verify your domain is active on Cloudflare
- Ensure proxy mode (orange cloud) is enabled
- Check that Cloudflare is properly routing traffic
Verify Country Detection:
You can test if Cloudflare headers are present by adding this temporary code to your theme’s functions.php:
add_action('wp_head', function() {
if (current_user_can('manage_options')) {
echo '<!-- CF Country: ' . ($_SERVER['HTTP_CF_IPCOUNTRY'] ?? 'Not detected') . ' -->';
}
});
Then visit any page while you are logged in as an admin.
Common Issues:
- Cloudflare not active: The most common cause – ensure Cloudflare is properly configured
- Direct IP access: Visitors accessing your server’s direct IP bypass Cloudflare
- Mixed configuration: Some DNS records not proxied through Cloudflare
Testing the Block
Safe Testing Method:
- Use a VPN to simulate traffic from a blocked country
- Try accessing your website
- You should see an HTTP 403 Forbidden error
- Switch VPN to an allowed country – site should load normally
Important: Always test with a VPN or proxy, never block your own actual country!
Best Practices
Security Considerations
- Admin Access: Ensure you never block countries from which you need admin access
- False Positives: Be aware that VPN users may appear to be from blocked countries
- Legal Compliance: Ensure country blocking complies with your local laws and regulations
Performance Tips
- Limit Countries: Only block countries that are genuinely problematic for your site
- Monitor Logs: Check your server logs to ensure legitimate traffic isn’t being blocked
- Regular Review: Periodically review your blocked country list
Maintenance
- Backup First: AdminEase creates automatic backups, but manual backups are recommended
- Test Changes: Always test country blocking rules after making changes
- Monitor Traffic: Keep an eye on your analytics to ensure desired traffic isn’t affected
Removing Country Blocks
To Disable Feature:
- Go to AdminEase → Security
- Toggle Block Specific Countries to OFF
- Click Save Settings
- The blocking rules will be automatically removed from your
.htaccessfile
To Modify Blocked Countries:
- Simply update the country selection in the dropdown field
- Save settings
- Rules will be automatically updated
Support
If you encounter issues with the country blocking feature:
- Verify Cloudflare Setup: Ensure Cloudflare is properly configured and active
- Check Server Compatibility: Ensure your server supports
.htaccessandmod_rewrite - Review Error Logs: Check your server’s error logs for any related issues
- Contact Support: Reach out to AdminEase support with specific error messages by opening a support ticket.
For additional help, contact our support team.
This feature works best with Cloudflare.