RewriteEngine On

########################################
# 1. BLOK REQUEST TANPA USER-AGENT
# (90% spam klik domain)
########################################
RewriteCond %{HTTP_USER_AGENT} ^-?$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^.*$ - [F,L]

########################################
# 2. BLOK SPAM KLIK DOMAIN UTAMA (/)
########################################
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_REFERER} ^$
RewriteCond %{HTTP_USER_AGENT} !Mozilla [NC]
RewriteRule ^ - [F,L]

########################################
# 3. BLOK BOT & SCANNER UMUM
########################################
RewriteCond %{HTTP_USER_AGENT} (bot|spider|crawler|scanner|curl|wget|python|nikto|sqlmap|nmap|masscan|ahrefs|semrush) [NC]
RewriteRule ^.*$ - [F,L]

########################################
# 4. SEMBUNYIKAN .html (AMAN & TERBATAS)
########################################

# Redirect jika .html diketik (bersihkan URL)
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?]
RewriteRule ^ %1 [R=301,L]

# Jalankan hanya file .html yang BENAR-BENAR ADA
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ $1.html [L]

########################################
# 5. BLOK FILE & PATH SENSITIF
########################################
RewriteCond %{REQUEST_URI} (\.env|\.git|wp-admin|wp-login|xmlrpc|phpmyadmin) [NC]
RewriteRule ^.*$ - [F,L]

<FilesMatch "\.(log|ini|bak|config|env|sql|sh)$">
Deny from all
</FilesMatch>

########################################
# 6. MATIKAN DIRECTORY LISTING
########################################
Options -Indexes

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php84” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php84___lsphp .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
