Cloudflare Bot Protection Setup
Step 1: Create Verified Bot Rule
- Go to Cloudflare Dashboard → Security → WAF
- Click Custom rules → Create rule
- Rule name: Allow Verified Search Engines
- Click Edit expression
- Paste this expression:
(cf.client.bot) or (cf.verified_bot_category in {"AI Search" "AI Assistant" "Search Engine Crawler" "Advertising & Marketing"}) or (http.user_agent contains "OAI-SearchBot") or (http.user_agent contains "PerplexityBot") or (http.user_agent contains "ChatGPT-User") or (ip.src eq 118.179.207.90) or (ip.src.asnum in {63034 15169 36040})
- Action: Select Skip
- Check all boxes:
- ✅ All remaining custom rules
- ✅ All rate limiting rules
- ✅ All managed rules
- ✅ All Super Bot Fight Mode Rules
- Place at: First
- Click Save
Part 2: Cloudflare Cache Settings
Step 2: Set Browser Cache TTL
- Go to Caching → Configuration
- Find Browser Cache TTL
- Set to 1 day (24 hours)
- Click Save
Step 3: Create Static Assets Cache Rule
- Go to Caching → Cache Rules
- Click Create Rule
- Rule name: Long Cache for Static Assets
- Click Edit expression
- Paste this expression:
(http.request.uri.path.extension in {"jpg" "jpeg" "png" "gif" "webp" "svg" "css" "js" "ico" "woff" "woff2" "ttf" "eot" "mp4"})
- Set Browser Cache TTL: 1 month
- Set Edge Cache TTL: 1 month
- Click Save
Step 4: Purge Cache
- Go to Caching → Configuration
- Scroll down and click Purge Everything
- Confirm
Part 3: Database Cleanup (phpMyAdmin)
Step 5: Clean Post Views Table
- Open phpMyAdmin
- Select your WordPress database
- Click SQL tab
- Run this query:
DELETE FROM wp_post_views WHERE period < DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 30 DAY), '%Y%m%d');
- Run this query:
OPTIMIZE TABLE wp_post_views;
Step 6: Clean Rank Math Analytics
- Run this query:
DELETE FROM wp_rank_math_analytics_gsc WHERE created < DATE_SUB(NOW(), INTERVAL 60 DAY);
- Run this query:
OPTIMIZE TABLE wp_rank_math_analytics_gsc;
Step 7: Clean Rank Math Inspections
- Run this query:
DELETE FROM wp_rank_math_analytics_inspections WHERE created < DATE_SUB(NOW(), INTERVAL 60 DAY);
- Run this query:
OPTIMIZE TABLE wp_rank_math_analytics_inspections;
Step 8: Check Your Results
- Click Structure tab in phpMyAdmin
- Scroll to bottom to see new total database size
- Expected: 320-350 MB (from ~500 MB)
Part 4: WordPress Configuration
Step 9: Update wp-config.php
- Go to your hosting control panel → File Manager
- Navigate to /public_html/
- Right-click wp-config.php → Edit
- Add these lines before /* That’s all, stop editing! */:
// Disable post revisions
define('WP_POST_REVISIONS', false);
// Auto-delete trash after 7 days
define('EMPTY_TRASH_DAYS', 7);
- Click Save
Step 10: Set Rank Math Data Retention
- WordPress Dashboard → Rank Math → General Settings
- Click Analytics tab
- Find “Data Retention Period”
- Set to 60 days
- Click Save Changes
Part 5: Schedule Regular Maintenance
Step 11: Set Calendar Reminders
Set reminders to run these queries every 3 months:
Clean old post views (keep last 30 days)
DELETE FROM wp_post_views
WHERE period < DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 30 DAY), '%Y%m%d');
OPTIMIZE TABLE wp_post_views;
Clean old Rank Math data (keep last 60 days)
DELETE FROM wp_rank_math_analytics_gsc
WHERE created < DATE_SUB(NOW(), INTERVAL 60 DAY);
OPTIMIZE TABLE wp_rank_math_analytics_gsc;
DELETE FROM wp_rank_math_analytics_inspections
WHERE created < DATE_SUB(NOW(), INTERVAL 60 DAY);
OPTIMIZE TABLE wp_rank_math_analytics_inspections;
Expected Results
Database Size:
- Before: 500+ MB
- After: 320-350 MB
- Saved: ~150-180 MB
Performance Improvements:
✅ Faster page loads
✅ Reduced MySQL connections
✅ Better server performance
✅ Improved AdSense bot crawling
✅ Better PageSpeed scores
Quick Reference – Cleanup Schedule
| Task | Frequency |
|---|---|
| Database cleanup queries | Every 3 months |
| Check Cloudflare cache settings | Every 6 months |
| Review Rank Math data retention | When analytics grow large |
| Purge Cloudflare cache | After major site changes |
Troubleshooting
If Google Custom Search shows “No Results”:
- Wait 30 minutes after setting up Cloudflare bot rules
- Check Security → Events to confirm bots are being “Skipped”
- Verify CSE configuration at https://programmablesearchengine.google.com/
If database doesn’t shrink after OPTIMIZE:
- This is normal for InnoDB tables
- Space is freed internally but may not show immediately
- Performance improvements happen regardless
If AdSense earnings don’t improve:
- Give it 2-3 weeks for Google to recrawl
- Check ad placements (6-7 ads for 2000-word articles)
- Monitor PageSpeed scores
- Verify bots are accessing your site in Cloudflare logs
Done! ✅
Your WordPress site is now optimized for:
- Better performance
- Lower database bloat
- Improved AdSense revenue potential
- Efficient bot crawling
Recommended For You











