# AgriMboa - LiteSpeed/Apache config for Spaceship shared hosting
DirectoryIndex index.html index.php

<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

ErrorDocument 403 /index.html
ErrorDocument 404 /index.html

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # 1. Directly serve existing files and directories (with DirectoryIndex index.html)
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # 2. If a corresponding .html file exists, serve it
  RewriteCond %{DOCUMENT_ROOT}/$1.html -f
  RewriteRule ^(.+?)/?$ $1.html [L]

  # 3. If a corresponding folder with index.html exists, serve it
  RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
  RewriteRule ^(.+?)/?$ $1/index.html [L]

  # 4. Fallback to root index.html for SPA client-side routing
  RewriteRule ^ /index.html [L]
</IfModule>

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

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType text/html "access plus 1 hour"
</IfModule>

<IfModule mod_headers.c>
  Header always set Access-Control-Allow-Origin "*"
  Header always set X-Content-Type-Options "nosniff"
</IfModule>

AddType application/javascript .js
AddType text/css .css
AddType image/svg+xml .svg
AddType application/json .json
