# Apache / cPanel — deploy rules for arka.barname-nevisan.ir (static Vite export).
# Upload the contents of /dist to public_html (or a subdirectory).
# English comments only (project convention).

AddDefaultCharset UTF-8

# ─── MIME types ───────────────────────────────────────────────────────────────
<IfModule mod_mime.c>
  AddType application/javascript .js .mjs
  AddType text/css               .css
  AddType font/woff2             .woff2
  AddType font/woff              .woff
  AddType image/svg+xml          .svg
  AddType application/manifest+json .webmanifest
</IfModule>

# ─── Cache headers ────────────────────────────────────────────────────────────
# Vite hashes JS/CSS filenames → safe to cache forever.
<IfModule mod_headers.c>
  <LocationMatch "^/assets/.*\.(js|mjs|css)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </LocationMatch>
  <LocationMatch "^/assets/.*\.(woff2|woff)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </LocationMatch>
  # HTML must always be revalidated (no content hash in index.html name).
  <FilesMatch "\.html$">
    Header set Cache-Control "public, max-age=0, must-revalidate"
  </FilesMatch>
  # Security headers
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ─── Directory listing ────────────────────────────────────────────────────────
Options -Indexes

# ─── URL rewriting ────────────────────────────────────────────────────────────
<IfModule mod_rewrite.c>
  RewriteEngine On
  # If the app lives at the document root of arka.barname-nevisan.ir, leave
  # RewriteBase commented out.  For a subdirectory deploy set e.g.:
  # RewriteBase /arka/

  # Force HTTPS (disable if the host terminates SSL elsewhere and causes loops).
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

  # Single-page app fallback — serves index.html for any unknown path.
  # Keep this even for a single-route site; it handles trailing-slash variants.
  RewriteRule ^ /index.html [L]
</IfModule>

# ─── Custom error pages ───────────────────────────────────────────────────────
ErrorDocument 404 /404.html

# ─── GZIP / Brotli compression ────────────────────────────────────────────────
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE \
    text/html text/plain text/css \
    application/javascript application/json \
    image/svg+xml font/woff2 font/woff
</IfModule>
