# YOUR BRAND Finance Tracker
# Subdirectory deployment at /finance-tracker/.
# Compatible with cPanel Apache/LiteSpeed subdirectory deployments.

Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Enforce HTTPS without assuming the application is in the domain root.
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

    # Block direct web access to private application areas.
    RewriteRule ^(?:app|database|storage|cron|cli|docs|tests|views)(?:/|$) - [F,L,NC]

    # Block common sensitive file types anywhere in the application.
    RewriteRule (?:^|/)\.(?:env|git|svn|htaccess|htpasswd) - [F,L,NC]
    RewriteRule \.(?:sql|log|jsonl|ini|bak|backup|old|orig|dist|sh|yml|yaml|toml|pem|key)$ - [F,L,NC]

    # Block editor/backup artifacts.
    RewriteRule (?:~|\.swp|\.swo)$ - [F,L,NC]
</IfModule>

<IfModule mod_headers.c>
    Header always set X-Frame-Options "DENY"
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Cross-Origin-Opener-Policy "same-origin"
    Header always set Cross-Origin-Resource-Policy "same-origin"
    Header always set Permissions-Policy "camera=(self), microphone=(), geolocation=(), payment=()"

    # asset_url() appends a local file-version query parameter, making the
    # immutable cache policy safe across application releases.
    <FilesMatch "\.(?:css|js|png|jpg|jpeg|gif|webp|svg|ico|woff|woff2)$">
        Header set Cache-Control "public, max-age=604800, immutable"
    </FilesMatch>

    <FilesMatch "\.php$">
        Header set Cache-Control "no-store, private"
    </FilesMatch>
</IfModule>

<IfModule mod_mime.c>
    AddDefaultCharset UTF-8
</IfModule>

# Keep PHP entry points directly addressable; no front-controller rewrite is required.

ErrorDocument 403 /finance-tracker/403.php
ErrorDocument 404 /finance-tracker/404.php

<FilesMatch "^(?:config\.php|composer\.(?:json|lock)|package(?:-lock)?\.json|README(?:\.md)?)$">
    Require all denied
</FilesMatch>
