# ==============================================================================
# PT Duta Energi Mas Website V1.0 — Production Apache / cPanel Configuration
# ==============================================================================

Options -Indexes -MultiViews
ServerSignature Off

# Force UTF-8
AddDefaultCharset UTF-8

# ------------------------------------------------------------------------------
# Security Headers
# ------------------------------------------------------------------------------
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
    Header always set X-XSS-Protection "1; mode=block"
    Header always unset X-Powered-By
    Header always unset Server
</IfModule>

# ------------------------------------------------------------------------------
# Block Direct Access to Sensitive Files & Private Application Directories
# ------------------------------------------------------------------------------
<FilesMatch "(^\.|composer\.(json|lock)|\.sql$|\.env$|\.log$|\.bak$|\.ini$|\.sh$|README\.md|CHANGELOG\.md)">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

# ------------------------------------------------------------------------------
# URL Rewriting & Canonical Redirects
# ------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Block direct web access to private application directories
    RewriteRule ^(app|config|database|storage|languages|vendor)(/|$) - [F,L,NC]

    # Production HTTPS & non-www canonicalization (auto-applies on production domain only)
    RewriteCond %{HTTP_HOST} ^www\.jasaservicekompressor\.com$ [NC]
    RewriteRule ^ https://jasaservicekompressor.com%{REQUEST_URI} [R=301,L]

    RewriteCond %{HTTP_HOST} ^jasaservicekompressor\.com$ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
    RewriteRule ^ https://jasaservicekompressor.com%{REQUEST_URI} [R=301,L]

    # Admin front controller
    RewriteRule ^admin/?$ admin/index.php [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^admin/(.*)$ admin/index.php?route=$1 [L,QSA]

    # Installer front controller
    RewriteRule ^install/?$ install/index.php [L,QSA]

    # Public front controller (clean SEO URLs, sitemaps, robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L,QSA]
</IfModule>

# ------------------------------------------------------------------------------
# Compression (Gzip / Deflate)
# ------------------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/json image/svg+xml font/woff2
</IfModule>

# ------------------------------------------------------------------------------
# Browser Caching
# ------------------------------------------------------------------------------
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
</IfModule>
