# Crawlie — canonical URL enforcement.
#
# Forces every request onto exactly one canonical form:
#   http(s)://example.com/...   ->  https://www.example.com/...
#   http(s)://www.example.com/... (already https+www) -> served as-is
#
# Why this matters: search engines treat http://, https://, non-www, and www
# versions of a site as up to 4 separate URLs unless you tell them otherwise.
# Splitting traffic/links/ranking signals across those variants is a common,
# easy-to-miss technical SEO problem — this collapses them all onto one.
#
# This file only takes effect on Apache (or Apache-compatible) hosting with
# mod_rewrite enabled — which is the default on most shared hosting and on
# the backend-php/ setup elsewhere in this project. If you're on Nginx,
# Cloudflare, Netlify, Vercel, etc., use their own redirect/rules config
# instead (each platform has a "force https" and "redirect to www" option —
# search your host's docs for those exact terms); an .htaccess file has no
# effect there.
#
# IMPORTANT: if your site should canonicalize to the NON-www form instead
# (https://example.com, no www), delete the two RewriteCond/RewriteRule pairs
# below and replace them with the commented-out alternative at the bottom.

<IfModule mod_rewrite.c>
  RewriteEngine On

  # 1) Force HTTPS (covers plain http:// and any proxy that sets this header).
  # RewriteCond %{HTTPS} off
  # RewriteCond %{HTTP:X-Forwarded-Proto} !https
  # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # 2) Force the www subdomain.
  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # --- To canonicalize to non-www instead, comment out block (2) above and
  # --- uncomment this one:
  # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  # RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
</IfModule>

# Sensible defaults for a static site on Apache.
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
</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 image/svg+xml "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType text/css "access plus 7 days"
  ExpiresByType application/javascript "access plus 7 days"
</IfModule>
