# =============================================================================
# NOC dashboard SPA — Apache fallback for client-side routing
# =============================================================================
# Vite copies this file unchanged into public/noc/.htaccess on build.
# Apache (cPanel default) needs this so that visiting /noc/servers/123
# directly (or refreshing on that URL) returns /noc/index.html instead
# of a 404. The React Router inside the SPA then resolves the route.
#
# If the request maps to a real file (an asset like /noc/assets/foo.js)
# we serve it directly. Otherwise we hand it to index.html.
# =============================================================================

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /noc/

    # Serve existing files / directories unchanged (assets, favicon, etc.)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Anything else falls back to the SPA entry point.
    RewriteRule ^ index.html [L]
</IfModule>

# Pre-compressed static assets — Vite's content-hashed bundles are
# immutable, so we can mark them long-cache. Cache busting is automatic
# because the filename hash changes when the content changes.
<IfModule mod_headers.c>
    <FilesMatch "\.(js|css|woff2?|ttf|otf|eot|svg|png|jpe?g|gif|webp)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    <FilesMatch "\.html$">
        # index.html must NOT be cached aggressively — it's how clients
        # find out about a new build's hashed asset URLs.
        Header set Cache-Control "no-cache, no-store, must-revalidate"
    </FilesMatch>
</IfModule>
