# Single-page client fallback for Apache / cPanel hosting.
# Every route that is not a real file or directory is served by index.html,
# so deep links like /admin, /panel or /category/sportswear survive a refresh.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Never rewrite existing files, directories or symlinks (assets, images, api files)
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d [OR]
  RewriteCond %{REQUEST_FILENAME} -l
  RewriteRule ^ - [L]

  # Leave server/API endpoints alone
  RewriteRule ^api/ - [L]
  RewriteRule ^_serverFn/ - [L]

  # Everything else falls back to the app shell
  RewriteRule . /index.html [L]
</IfModule>

<IfModule mod_mime.c>
  AddType application/javascript .js .mjs
  AddType text/css .css
  AddType image/svg+xml .svg
  AddType image/webp .webp
  AddType application/json .json
</IfModule>

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

<IfModule mod_expires.c>
  ExpiresActive On
  # Hashed build assets can be cached hard
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType image/webp "access plus 6 months"
  ExpiresByType image/png "access plus 6 months"
  ExpiresByType image/jpeg "access plus 6 months"
  # The shell must always be revalidated so new deploys show up
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "index\.html$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>
</IfModule>
