Options -Indexes

# ── 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 unset Server
    Header unset X-Powered-By
</IfModule>

# ── Block direct download of sensitive files ──────────────────────────────────
<FilesMatch "(^\.env|config\.php|composer\.(json|lock)|package\.json|installed\.lock)">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Block .install_token from being downloaded via HTTP
<Files ".install_token">
    Order Allow,Deny
    Deny from all
</Files>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # ── RewriteBase: change /1/ to / for cPanel root install, keep /subdirname/ for subdirectory ──
    RewriteBase /

    # ── install/, sw.js, ping_internet.php always pass through ───────────────
    RewriteRule ^install/            -  [L]
    RewriteRule ^ping_internet\.php$ -  [L]
    RewriteRule ^sw\.js$             -  [L]
    RewriteRule ^manifest\.php$      -  [L]
    RewriteRule ^offline\.php$       -  [L]

    # ── Public frontend routes that shadow physical directories/files ─────────
    # Must come BEFORE the real-file pass-through so the physical /tests/ dir
    # doesn't get served as a directory listing (403) instead of the tests page.
    RewriteRule ^tests/?$                      public/index.php?page=tests [L,QSA]

    # ── Real files and directories always pass through ────────────────────────
    RewriteCond %{REQUEST_FILENAME} -f  [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # ── Block direct HTTP download of includes/ (Apache-level) ───────────────
    RewriteRule ^includes/ - [F,L]

    # ── Standard public-site routing (post-install) ───────────────────────────
    RewriteRule ^$                             index.php [L]
    RewriteRule ^verify/?$                     verify.php [L,QSA]
    RewriteRule ^about/?$                      public/index.php?page=about [L,QSA]
    RewriteRule ^booking/?$                    public/booking.php [L,QSA]
    RewriteRule ^report-check/?$               public/report-check.php [L,QSA]
    RewriteRule ^report/verify/([0-9]+)/?$     public/report-verify.php?id=$1 [L,QSA]
    RewriteRule ^contact/?$                    public/index.php?page=contact [L,QSA]
</IfModule>

# ── GZIP Compression ──────────────────────────────────────────────────────────
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
    AddOutputFilterByType DEFLATE application/json application/xml application/xhtml+xml
    AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf font/woff font/woff2
</IfModule>

# ── Browser Caching ───────────────────────────────────────────────────────────
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg        "access plus 1 month"
    ExpiresByType image/png         "access plus 1 month"
    ExpiresByType image/gif         "access plus 1 month"
    ExpiresByType image/webp        "access plus 1 month"
    ExpiresByType image/svg+xml     "access plus 1 month"
    ExpiresByType image/x-icon      "access plus 1 year"
    ExpiresByType font/ttf          "access plus 1 year"
    ExpiresByType font/otf          "access plus 1 year"
    ExpiresByType font/woff         "access plus 1 year"
    ExpiresByType font/woff2        "access plus 1 year"
    ExpiresByType text/css          "access plus 1 week"
    ExpiresByType text/javascript   "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType text/html         "access plus 0 seconds"
</IfModule>

# ── PHP Settings ──────────────────────────────────────────────────────────────
<IfModule mod_php.c>
    php_flag  display_errors      Off
    php_flag  log_errors          On
    php_value upload_max_filesize 10M
    php_value post_max_size       12M
    php_value max_execution_time  60
    php_value session.cookie_httponly 1
    php_value session.use_strict_mode 1
</IfModule>
<IfModule mod_php8.c>
    php_flag  display_errors      Off
    php_flag  log_errors          On
    php_value upload_max_filesize 10M
    php_value post_max_size       12M
    php_value max_execution_time  60
    php_value session.cookie_httponly 1
    php_value session.use_strict_mode 1
</IfModule>
