# Apache config for the standalone/VPS build (`SEO=true`) — PM2 runs
# `next start` on 127.0.0.1:8001, Apache reverse-proxies everything
# to it except static assets it can serve straight off disk.
# Generated by scripts/generate-htaccess.mjs (runs via the "prebuild" npm hook,
# port from HTACCESS_PROXY_PORT or `node scripts/generate-htaccess.mjs <port>`,
# defaults to 8001) — edit that script, not this file directly, it
# gets overwritten on every build.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^favicon\.ico$ - [L]

    # Allow SSL certificate verification
    RewriteRule ^.well-known/acme-challenge/(.*) /.well-known/acme-challenge/$1 [L]

    # Serve Next.js STATIC files directly from filesystem (JS/CSS bundles).
    # Only _next/static/ — not all of _next/ (data/image requests still need the proxy).
    RewriteRule ^_next/static/(.*) /.next/static/$1 [L]

    # Proxy Next.js DATA requests to the Node process (required for client-side navigation).
    RewriteRule ^_next/data/(.*) http://127.0.0.1:8001/_next/data/$1 [P,L]

    # Serve public/'s own static files directly.
    RewriteCond %{REQUEST_URI} \.(js|css|svg|jpg|jpeg|png|gif|ico|woff|woff2|ttf|eot|webp|mp4|webm)$
    RewriteRule ^ - [L]

    # Forward everything else to the Node process.
    RewriteRule ^index.html http://127.0.0.1:8001/$1 [P]
    RewriteRule ^index.php http://127.0.0.1:8001/$1 [P]
    RewriteRule ^/?(.*)$ http://127.0.0.1:8001/$1 [P]
</IfModule>
