Options -Indexes
Options -MultiViews

# Force HTTPS (cPanel / Let's Encrypt)
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# PHP settings — mod_php variants (CGI / mod_php mode)
# On PHP-FPM hosts these are ignored; public/.user.ini handles those.
<IfModule mod_php8.c>
    php_flag  display_errors        Off
    php_value session.gc_maxlifetime 3600
    php_value session.cookie_httponly 1
    php_flag  session.use_strict_mode 1
    php_flag  session.cookie_secure   1
    php_value session.cookie_samesite Strict
</IfModule>
<IfModule mod_php7.c>
    php_flag  display_errors        Off
    php_value session.gc_maxlifetime 3600
    php_value session.cookie_httponly 1
    php_flag  session.use_strict_mode 1
    php_flag  session.cookie_secure   1
    php_value session.cookie_samesite Strict
</IfModule>
<IfModule mod_php.c>
    php_flag  display_errors        Off
    php_value session.gc_maxlifetime 3600
    php_value session.cookie_httponly 1
    php_flag  session.use_strict_mode 1
    php_flag  session.cookie_secure   1
    php_value session.cookie_samesite Strict
</IfModule>

# Security headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options  "nosniff"
    Header always set X-Frame-Options          "SAMEORIGIN"
    Header always set X-XSS-Protection         "1; mode=block"
    Header always set Referrer-Policy          "strict-origin-when-cross-origin"
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</IfModule>

# Prevent direct access to sensitive files and extensions
# Apache 2.4+ syntax
<IfVersion >= 2.4>
    <FilesMatch "\.(env|log|sql|db|db-shm|db-wal|sh|md|ini|json|lock)$">
        Require all denied
    </FilesMatch>
</IfVersion>

# Apache 2.2 fallback (mod_access_compat)
<IfVersion < 2.4>
    <FilesMatch "\.(env|log|sql|db|db-shm|db-wal|sh|md|ini|json|lock)$">
        Order allow,deny
        Deny from all
    </FilesMatch>
</IfVersion>

# Cache static assets
<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/jpeg            "access plus 1 month"
    ExpiresByType image/svg+xml         "access plus 1 month"
    ExpiresByType font/woff2            "access plus 1 year"
</IfModule>

# Gzip compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>

# Custom 404
ErrorDocument 404 /404.php
