# Forums Earl Haig - .htaccess
# https://forums.earlhaig.ca/
# Force HTTPS, non-www, compression, security headers, cache

# Force HTTPS and canonical host
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

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

  # Non-www redirect (canonical: forums.earlhaig.ca without www)
  RewriteCond %{HTTP_HOST} ^www\.forums\.earlhaig\.ca [NC]
  RewriteRule ^ https://forums.earlhaig.ca%{REQUEST_URI} [L,R=301]
</IfModule>

# Gzip compression (HTML, CSS, JS, JSON, XML, SVG, PNG)
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json application/xml image/svg+xml image/png
</IfModule>

# Security headers
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set X-XSS-Protection "1; mode=block"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>

# Cache static assets
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType application/javascript "access plus 1 week"
</IfModule>

# Prevent directory listing
Options -Indexes

# Default charset
AddDefaultCharset UTF-8
