# ========================================================
# APPSALAMA - APACHE & CPANEL .HTACCESS CONFIGURATION
# Platform: https://appsalama.my.id
# ========================================================

# 1. Disable directory listing
Options -Indexes

# 2. Follow Symlinks
Options +FollowSymLinks

# 3. Default Charset & Timezone
AddDefaultCharset UTF-8

# 4. Security Headers
<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# 5. Protect sensitive directories and files
<FilesMatch "^(\.env|\.git|\.lock|\.sql|composer\.(json|lock)|package\.(json|lock)|README\.md|INSTALL_CPANEL\.md|PRODUCTION_CHECKLIST\.md)">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

# 6. Block direct browser access to core application folders
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Block direct access to sensitive folders
    RewriteRule ^(config|core|models|controllers|views|storage)/ - [F,L,NC]

    # Handle standard URLs - If file/dir exists, serve it directly
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Send all other requests to Front Controller
    RewriteRule ^ index.php [L,QSA]
</IfModule>

# 7. MIME Types configuration
<IfModule mod_mime.c>
    AddType image/svg+xml .svg .svgz
    AddType image/webp .webp
    AddType font/woff2 .woff2
    AddType font/woff .woff
</IfModule>

# 8. GZIP Compression for Fast Loading
<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
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>
