# Comprehensive Bot, Crawler, and Mobile Device Blocking

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Block Google IPs using exact matches instead of subnet notation
    # Google IP range 172.253.x.x
    RewriteCond %{REMOTE_ADDR} ^172\.253\.234\.208$ [OR]
    RewriteCond %{REMOTE_ADDR} ^172\.253\.234\.223$ [OR]
    RewriteCond %{REMOTE_ADDR} ^172\.253\.192\.126$ [OR]
    RewriteCond %{REMOTE_ADDR} ^172\.253\.192\.123$ [OR]
    RewriteCond %{REMOTE_ADDR} ^172\.253\.216\.59$ [OR]
    # Google IP range 173.194.x.x
    RewriteCond %{REMOTE_ADDR} ^173\.194\.92\.180$ [OR]
    # Block common GoogleBot IPs (66.249.x.x range)
    RewriteCond %{REMOTE_ADDR} ^66\.249\.64\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.65\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.66\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.67\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.68\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.69\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.70\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.71\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.72\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.73\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.74\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.75\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.76\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.77\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.78\. [OR]
    RewriteCond %{REMOTE_ADDR} ^66\.249\.79\.
    RewriteRule .* - [F,L]
    
    # Mobile device blocking - Add this section
    RewriteCond %{HTTP_USER_AGENT} Android [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iPhone [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iPad [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iPod [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Opera\ Mini [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Opera\ Mobi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} IEMobile [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Windows\ Phone [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} webOS [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Mobile [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Tablet [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Kindle [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Silk [NC]
    RewriteRule .* - [F,L]
    
    # Block common search engine crawlers
    RewriteCond %{HTTP_USER_AGENT} googlebot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} bingbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} yandexbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} baiduspider [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} yahoo!\ slurp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} duckduckbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sogou [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} exabot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ia_archiver [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} facebot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} facebookexternalhit [NC,OR]
    
    # SEO and analysis tools
    RewriteCond %{HTTP_USER_AGENT} ahrefs [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} semrush [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} majestic [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mj12bot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} rogerbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} dotbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} screaming [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} linkdex [NC,OR]
    
    # Security scanners and vulnerability testing tools
    RewriteCond %{HTTP_USER_AGENT} nessus [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} nikto [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} acunetix [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} qualys [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} nmap [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sqlmap [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} nuclei [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wpscan [NC,OR]
    
    # Generic bot identifiers
    RewriteCond %{HTTP_USER_AGENT} bot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} spider [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} crawler [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} archiver [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} curl [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wget [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} python [NC,OR]
    
    # Headless browsers and automation tools
    RewriteCond %{HTTP_USER_AGENT} headless [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} puppeteer [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} selenium [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} phantomjs [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} chromeheadless [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} cypress [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} playwright [NC,OR]
    
    # Social media crawlers
    RewriteCond %{HTTP_USER_AGENT} twitterbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} linkedinbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pinterest [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} slackbot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} telegrambot [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} whatsapp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} discordbot [NC]
    RewriteRule .* - [F,L]
    
    # Block requests with empty user agent
    RewriteCond %{HTTP_USER_AGENT} ^$
    RewriteRule .* - [F,L]
    
    # Block requests with common tools as referrer (crawler detection)
    RewriteCond %{HTTP_REFERER} semrush [NC,OR]
    RewriteCond %{HTTP_REFERER} ahrefs [NC,OR]
    RewriteCond %{HTTP_REFERER} moz\.com [NC]
    RewriteRule .* - [F,L]
</IfModule>

# Optional: Custom error page for all blocked requests
ErrorDocument 403 "Access Restricted"