# .htaccess
# Mengaktifkan mod rewrite
RewriteEngine On

# ============================================
# 1. MENGHAPUS EKSTENSI .php DARI URL
# ============================================
# Contoh: domain.com/halaman.php -> domain.com/halaman

# Memastikan file/direktori tidak benar-benar ada
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

# Mengarahkan permintaan tanpa ekstensi ke file .php
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# ============================================
# 2. HALAMAN 404 KHUSUS
# ============================================
# Menampilkan halaman 404.php jika file tidak ditemukan

ErrorDocument 404 /404.php

# ============================================
# 3. REDIRECT HTTPS (Opsional - Aktifkan jika pakai SSL)
# ============================================
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# ============================================
# 4. REDIRECT WWW ke NON-WWW (Opsional)
# ============================================
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# ============================================
# 5. MEMBLOKIR AKSES KE FILE/FOLDER TERTENTU
# ============================================

# Blokir akses langsung ke folder config
<IfModule mod_rewrite.c>
    RewriteRule ^config/ - [F,L]
</IfModule>

# Blokir akses ke file .php di folder includes
<FilesMatch "includes/.*\.php$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# ============================================
# 6. PENGATURAN KECEPATAN & CACHE
# ============================================

# Kompres file untuk loading lebih cepat
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/javascript application/javascript application/x-javascript application/json
</IfModule>

# Cache browser untuk file statis
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
</IfModule>

# ============================================
# 7. KEAMANAN DASAR
# ============================================

# Mencegah listing direktori
Options -Indexes

# Melindungi file .htaccess
<Files .htaccess>
    Order Allow,Deny
    Deny from all
</Files>

# Mencegah akses ke file yang dimulai dengan titik (.)
<FilesMatch "^\.">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Header keamanan tambahan
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>