# Long Cheng Plaza, Apache / cPanel config for the Vite SPA build.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Force HTTPS
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # robots.txt and the sitemaps are generated (they carry the live host and the
  # published rows), so they are claimed before the static-file check below,
  # a stale robots.txt sitting in the web root must not win.
  RewriteRule ^robots\.txt$ /robots.php [L]
  RewriteRule ^sitemap\.xml$ /sitemap.php [L]
  RewriteRule ^sitemap-([a-z]+)\.xml$ /sitemap.php?type=$1 [L,QSA]

  # Document requests go through seo.php, which injects the per-page title,
  # description, canonical, Open Graph, Twitter and JSON-LD tags into
  # index.html before serving it. Social scrapers do not run JavaScript, so
  # this is the only thing that makes a shop page preview differently from a
  # blog post. seo.php falls back to the untouched index.html if anything at
  # all goes wrong, so the SPA fallback behaviour is unchanged.
  RewriteCond %{REQUEST_URI} !^/api/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /seo.php [L]
</IfModule>

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/xml
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On

  # Hashed build assets are immutable
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"

  # The entry document must always be revalidated
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(css|js|jpg|jpeg|png|webp|svg|woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.html$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>

  # seo.php emits the document itself and sends its own ETag/Last-Modified, so
  # it must be revalidated like index.html rather than cached as a "script".
  <FilesMatch "^seo\.php$">
    Header set Cache-Control "public, max-age=0, must-revalidate"
  </FilesMatch>

  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

ErrorDocument 404 /index.html
