# ============================================
# ✅ Aktifkan mod_rewrite
# ============================================
RewriteEngine On

# ============================================
# 🚫 Blokir robots.txt (404)
# ============================================
RewriteRule ^robots\.txt$ - [R=404,L]

# ============================================
# ✅ Batasi akses sitemap.xml hanya untuk Googlebot
# ============================================
<IfModule mod_setenvif.c>
<IfModule mod_authz_core.c>
    <Files "sitemap.xml">
        Require all denied

        SetEnvIfNoCase User-Agent "Googlebot" allowed_bot
        SetEnvIfNoCase User-Agent "Googlebot-Image" allowed_bot
        SetEnvIfNoCase User-Agent "Googlebot-News" allowed_bot
        SetEnvIfNoCase User-Agent "Googlebot-Video" allowed_bot
        SetEnvIfNoCase User-Agent "Google-Site-Verification" allowed_bot

        Require env allowed_bot

        <IfModule mod_headers.c>
            Header set Content-Type "application/xml"
        </IfModule>
    </Files>
</IfModule>
</IfModule>

# ============================================
# ✅ SPA routing (React, Vue, dll)
# ============================================
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(robots\.txt|sitemap\.xml)$
RewriteCond %{REQUEST_URI} !\.(png|jpg|jpeg|webp|gif|svg|ico)$
RewriteRule . /index.html [L]

# ============================================
# ✅ Browser Cache Optimization (SEO + Speed)
# ============================================
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>
