# ===========================================================
# I AutoFin - cPanel Apache Configuration
# Optimized for cPanel, Shared Hosting, Cloud & VPS Environments
# ===========================================================

Options -Indexes
Options +FollowSymLinks

# Set Default Charset
AddDefaultCharset UTF-8

# Prevent directory listings and protect sensitive files
<FilesMatch "^\.|\.json$|\.lock$|\.md$|composer\.">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

# Protect config.php direct viewing (handled via PHP)
<Files "config.php">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</Files>

# Protect Database SQL Dumps from public HTTP downloads
<FilesMatch "\.(sql|sqlite)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

# Core Routing Engine
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Disable TRACE method
    RewriteCond %{REQUEST_METHOD} ^TRACE
    RewriteRule .* - [F]

    # Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Do not rewrite if real file or directory exists
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Forward all other requests to index.php
    RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

# 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>

# MIME Types for Web Fonts & SVG
<IfModule mod_mime.c>
    AddType image/svg+xml .svg .svgz
    AddType font/woff2 .woff2
    AddType font/woff .woff
    AddType font/ttf .ttf
</IfModule>

# Gzip Compression for Fast Loading
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml
</IfModule>