# ─────────────────────────────────────────────
#  FourioSolutions — Performance .htaccess
#  Namecheap Stellar (Apache / LiteSpeed)
# ─────────────────────────────────────────────

# ── 1. Enable GZIP Compression ──────────────
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE application/json application/xml application/xhtml+xml
  AddOutputFilterByType DEFLATE image/svg+xml font/woff font/woff2
</IfModule>

# ── 2. Browser Caching ───────────────────────
<IfModule mod_expires.c>
  ExpiresActive On

  # Images — 6 months
  ExpiresByType image/webp             "access plus 6 months"
  ExpiresByType image/png              "access plus 6 months"
  ExpiresByType image/jpeg             "access plus 6 months"
  ExpiresByType image/gif              "access plus 6 months"
  ExpiresByType image/svg+xml         "access plus 6 months"
  ExpiresByType image/x-icon          "access plus 1 year"

  # Fonts — 1 year
  ExpiresByType font/woff              "access plus 1 year"
  ExpiresByType font/woff2             "access plus 1 year"
  ExpiresByType application/font-woff  "access plus 1 year"

  # CSS / JS — 1 month
  ExpiresByType text/css               "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/javascript        "access plus 1 month"

  # HTML — 1 hour (so updates show quickly)
  ExpiresByType text/html              "access plus 1 hour"
</IfModule>

# ── 3. Cache-Control Headers ─────────────────
<IfModule mod_headers.c>
  <FilesMatch "\.(webp|png|jpg|jpeg|gif|ico|svg)$">
    Header set Cache-Control "public, max-age=15552000, immutable"
  </FilesMatch>
  <FilesMatch "\.(woff|woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "public, max-age=2592000"
  </FilesMatch>
  # Security headers
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ── 4. WebP MIME type (if not registered) ────
AddType image/webp .webp

# ── 5. Keep-Alive ────────────────────────────
<IfModule mod_headers.c>
  Header set Connection keep-alive
</IfModule>

# ── 6. Remove ETags (avoid double validation) ─
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>
FileETag None

# ── 7. Disable directory listing ─────────────
Options -Indexes

# ── 8. Force HTTPS (enable after SSL active) ─
# <IfModule mod_rewrite.c>
#   RewriteEngine On
#   RewriteCond %{HTTPS} off
#   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# </IfModule>
