<IfModule mod_rewrite.c>
    RewriteEngine On

    # ─── Force HTTPS (uncomment in production if you have SSL) ───
    # RewriteCond %{HTTPS} off
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # ─── Remove www (choose one: www or non-www) ───
    # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    # RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

    # ─── Serve existing files/directories directly ───
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # ─── Route everything else to index.php ───
    RewriteRule ^ index.php [QSA,L]
</IfModule>

# ─── Security Headers ───
<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"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ─── Enable Compression ───
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

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

# Prevent directory listing
Options -Indexes

# Deny access to index.php directly showing source
<Files "*.php">
    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</Files>
