<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # If the request is for an existing file or directory, serve it directly
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  # Route social media crawlers to the SSR meta-tag edge function for the homepage
  RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit|Facebot|Twitterbot|LinkedInBot|Slackbot|TelegramBot|Discordbot|WhatsApp|Pinterest|redditbot|Applebot|Googlebot|bingbot) [NC]
  RewriteCond %{REQUEST_URI} ^/?$
  RewriteRule ^ https://lpntxqncvgbexesxjprd.supabase.co/functions/v1/og-store?path=%{REQUEST_URI} [P,L]

  # Otherwise, redirect all requests to index.html
  RewriteRule ^ index.html [QSA,L]
</IfModule>

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

# Cache static assets
<IfModule mod_expires.c>
  ExpiresActive On
  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/svg+xml "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
