# Apache Configuration for Permohonan Salinan Putusan
# Pengadilan Negeri Watampone

# Enable URL Rewriting
RewriteEngine On

# Allow direct access to static files (images, css, js) - IMPORTANT!
RewriteCond %{REQUEST_URI} \.(png|jpg|jpeg|gif|css|js|ico|svg|webp)$ [NC]
RewriteRule ^(.*)$ - [L]

# Set no-cache headers for images during development
<FilesMatch "\.(png|jpg|jpeg|gif|svg|webp)$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
</FilesMatch>

# Redirect all other requests to public directory (except static files)
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_URI} !\.(png|jpg|jpeg|gif|css|js|ico|svg|webp)$ [NC]
RewriteRule ^(.*)$ public/setup.php [L,QSA]

# Security: Block access to sensitive files
<Files ".env">
    Order allow,deny
    Deny from all
</Files>

<Files "*.php~">
    Order allow,deny
    Deny from all
</Files>

<Files "*.log">
    Order allow,deny
    Deny from all
</Files>

# Set proper MIME types
<IfModule mod_mime.c>
    AddType application/javascript .js
    AddType text/css .css
</IfModule>

# Enable compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# Set cache headers
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/ico "access plus 1 month"
    ExpiresByType image/icon "access plus 1 month"
    ExpiresByType text/plain "access plus 1 month"
</IfModule>
