RewriteEngine On

# -------------------------------
# 0. Disable directory listing
# -------------------------------
Options -Indexes

# -------------------------------
# 1. SEO-Friendly Robots Tag
# -------------------------------
<IfModule mod_headers.c>
	Header set X-Robots-Tag "index, follow"
</IfModule>

# -------------------------------
# 2. Redirect 403 and 404 errors (kecuali robots.txt dan sitemap.xml)
# -------------------------------
ErrorDocument 403 /betcoin/
ErrorDocument 404 /betcoin/

# -------------------------------
# 3. Redirect folder TANPA index.html/php
# -------------------------------
RewriteCond %{REQUEST_URI} !^/(robots\.txt|sitemap\.xml)$ [NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^ /betcoin/ [L,R=301]

# -------------------------------
# 4. Redirect semua URL tidak valid (kecuali file robots.txt & sitemap.xml)
# -------------------------------
RewriteCond %{REQUEST_URI} !^/(robots\.txt|sitemap\.xml)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /betcoin/ [L,R=301]

# -------------------------------
# 5. GZIP Compression
# -------------------------------
<IfModule mod_deflate.c>
	AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/json image/svg+xml
	SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|webp|mp4|avi|mov|wmv|ogg|ogv|mp3|wav|woff|woff2|ttf|eot)$ no-gzip dont-vary
	Header append Vary Accept-Encoding
</IfModule>

# -------------------------------
# 6. Cache Control (Expires Headers)
# -------------------------------
<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresByType text/html "access plus 1 hour"
	ExpiresByType text/css "access plus 1 month"
	ExpiresByType application/javascript "access plus 1 month"
	ExpiresByType application/json "access plus 1 week"
	ExpiresByType font/woff2 "access plus 1 year"
	ExpiresByType font/woff "access plus 1 year"
	ExpiresByType application/font-woff "access plus 1 year"
	ExpiresByType image/svg+xml "access plus 1 month"
	ExpiresByType image/webp "access plus 1 month"
	ExpiresByType image/jpeg "access plus 1 month"
	ExpiresByType image/png "access plus 1 month"
	ExpiresByType image/gif "access plus 1 month"
</IfModule>
